Skip to content

Instantly share code, notes, and snippets.

@samueltardieu
Created April 2, 2024 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueltardieu/704823a4f51104b0cff259f206f09b05 to your computer and use it in GitHub Desktop.
Save samueltardieu/704823a4f51104b0cff259f206f09b05 to your computer and use it in GitHub Desktop.
use tokio::time::Duration;
async fn value<T>(x: T, duration: Duration) -> T {
println!("Before sleeping in value");
tokio::time::sleep(duration).await;
println!("After sleeping in value");
x
}
async fn identity<T>(x: &mut T) -> &mut T {
println!("In identity");
x
}
#[tokio::main]
async fn main() {
let mut x = 0i32;
println!("Before assignment");
*identity(&mut x).await = value(42, Duration::from_secs(1)).await;
println!("After assignment");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment