问题
I have a function in a crate that returns old style futures.
Imagine something like:
pub fn old_function() -> impl Future<Item = X, Error = Y>
...
I want to use this crate in a new codebase where I don't want to mix things too much.
How can I keep the new implementation clean and use async/await
when calling this old_function
?
回答1:
The answer was very easy. I write here in case somebody has a similar problem. It is actually part of the async/await primer :)
You need to enable the compat feature
[dependencies]
futures = { version = "0.3.1", features = ["compat"] }
And later it is possible to do:
let x = old_function().compat().await;
来源:https://stackoverflow.com/questions/59976639/using-async-await-with-old-futureitem-x-error-y-types