Skip to content

Instantly share code, notes, and snippets.

@szabba
Forked from anonymous/playground.rs
Created July 24, 2015 19:54
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 szabba/ac2030897e5bd929880d to your computer and use it in GitHub Desktop.
Save szabba/ac2030897e5bd929880d 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