I'm trying to asynchronously invoke a Future
that is returned from a function. Is it possible?
use core::future::Future;
fn choose_your_adventure<'a>(i: usize) -> Box<&'a dyn Future<Output = ()>> {
match i {
0 => Box::new(&async {}),
_ => Box::new(&async {})
}
}
async fn does_not_work() -> () {
let choice = choose_your_adventure(0);
choice.await; // error[E0277]: `&dyn Future<Output = ()>` is not a future
}