Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 10, 2020 21:17
Show Gist options
  • Save rust-play/155373395c1ee4a649e14f51211e19d6 to your computer and use it in GitHub Desktop.
Save rust-play/155373395c1ee4a649e14f51211e19d6 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use core::future::Future;
async fn foo() -> u64 {
10
}
async fn bar(x: impl Future<Output = u64>) {
println!("{}", x.await);
}
fn baz() -> impl Future<Output = u64> {
let mut x: Vec<_> = vec![foo(), foo()];
let y: Vec<Box<dyn Future<Output = u64>>> = x.iter().map(|f| f.boxed()).collect();
x.pop().unwrap()
}
fn main() {
use futures::executor::block_on;
block_on(bar(foo()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment