Created
March 26, 2020 23:23
-
-
Save dhilst/62a43069fc86c0d864ed56f2c77295a7 to your computer and use it in GitHub Desktop.
This file contains 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 futures::future::Future; | |
struct MyStruct { | |
msg: String, | |
} | |
impl MyStruct { | |
fn new(msg: String) -> Self { MyStruct{ msg } } | |
} | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error + 'static>> { | |
let a = MyStruct::new("hello world".to_string()); | |
tokio::task::spawn(foo(&a)).await?; | |
Ok(()) | |
} | |
fn foo<'a>(ms: &'a MyStruct) -> impl Future<Output=()> + 'a { | |
async move { | |
println!("{}", &ms.msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment