Skip to content

Instantly share code, notes, and snippets.

@samueltardieu
Created April 2, 2024 08:34
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/004491e7bfd80b701f0cba09a65fff39 to your computer and use it in GitHub Desktop.
Save samueltardieu/004491e7bfd80b701f0cba09a65fff39 to your computer and use it in GitHub Desktop.
fn identity<T>(x: &mut T) -> &mut T {
println!("In identity");
x
}
fn main() {
let mut x = 0i32;
println!("Before assignment");
*identity(&mut x) = { println!("Evaluating 42"); 42 };
println!("After assignment");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment