【发布时间】:2019-10-29 16:13:06
【问题描述】:
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 未来并获得结果,但我可以导入的 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(())
}
【问题讨论】: