Is there a way that we can convert from futures 0.1 to the standard library futures?

后端 未结 1 1762
礼貌的吻别
礼貌的吻别 2020-12-07 04:03

The async/await feature is coming soon, but there are a lot of libraries still using futures 0.1. How do we convert between the two?

Conver

1条回答
  •  臣服心动
    2020-12-07 04:57

    Use the Future01CompatExt trait:

    use futures01::future as future01;
    use futures03::compat::Future01CompatExt;
    
    fn make_future_01() -> impl future01::Future {
        future01::ok(2)
    }
    
    async fn example_03_uses_01() -> Result {
        let v = make_future_01().compat().await?;
        Ok(v)
    }
    
    [dependencies]
    futures03 = { package = "futures", version = "0.3", features = ["compat"] }
    futures01 = { package = "futures", version = "0.1" }
    

    0 讨论(0)
提交回复
热议问题