Skip to content

Instantly share code, notes, and snippets.

@abakst
Created May 25, 2018 02:58
Show Gist options
  • Save abakst/9631c3480a1b67a31eb83ec1917d1057 to your computer and use it in GitHub Desktop.
Save abakst/9631c3480a1b67a31eb83ec1917d1057 to your computer and use it in GitHub Desktop.
fn main() {
let mut x = 1;
let mut y = 0;
{
let z = alias(&mut x,&mut y);
*z = 1;
}
println!("y is now {}", y);
}
fn alias<'a>(x:&'a mut i32, y:&'a mut i32) -> &'a mut i32 {
if *x == 0 {
x
} else {
y
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment