Created
January 10, 2020 21:17
-
-
Save rust-play/155373395c1ee4a649e14f51211e19d6 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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