Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2015 19:54
Show Gist options
  • Save anonymous/df37612b6029e573f8a9 to your computer and use it in GitHub Desktop.
Save anonymous/df37612b6029e573f8a9 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
// Can I have two mut references to different parts of a structure
// simultaneously?
struct Point {
x: f64,
y: f64,
}
fn main() {
let mut p = Point{x: 3.0, y: 5.0};
println!("({}, {})", p.x, p.y);
{
swap(&mut p.x, &mut p.y);
}
println!("({}, {})", p.x, p.y);
}
fn swap(a: &mut f64, b: &mut f64) {
let t = *b;
*b = *a;
*a = t;
}
// YES I CAN!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment