Created
April 2, 2024 08:42
-
-
Save samueltardieu/704823a4f51104b0cff259f206f09b05 to your computer and use it in GitHub Desktop.
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 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