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(())
}