Skip to content

Instantly share code, notes, and snippets.

@dhilst
Created March 26, 2020 23:23
Show Gist options
  • Save dhilst/62a43069fc86c0d864ed56f2c77295a7 to your computer and use it in GitHub Desktop.
Save dhilst/62a43069fc86c0d864ed56f2c77295a7 to your computer and use it in GitHub Desktop.
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