有没有一种方法可以将期货0.1转换为标准库期货?

问题描述 投票:0回答:1

async / await功能即将推出,但是仍有许多库仍在使用Futures 0.1。我们如何在两者之间转换?

[Convert an async future to 0.1 future涵盖了将异步将来转换为0.1将来。

How do I erase the type of future in the new future API?讨论了一个async函数,该函数调用0.1 Future并获取结果,但是我可以导入的await!()宏在哪里?似乎它不再编译。

struct A_future01;

impl A_future01 {
    pub fn exec1() -> Box<dyn Future<Item=String, Error=()>> {
        Box::new(futures::future::result("ok"))
    }

    pub fn exec2() -> Box<dyn Future<Item=String, Error=()>> {
        Box::new(call().unit_error().boxed().compat()) //Like this## Heading ##?
    }
}

async fn call() -> Result<(), Box<dyn std::error::Error>> {
    let result_from_a = A_future01::exec().await(); //how can I achieve this ?
    Ok(())
}
rust
1个回答
-1
投票
poll才能获得没有新的异步等待语言功能的结果。

请参见Tokio: Implementing futures

© www.soinside.com 2019 - 2024. All rights reserved.