Skip to content

Instantly share code, notes, and snippets.

Created January 31, 2016 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/7a96aaea08d131e3edb3 to your computer and use it in GitHub Desktop.
Save anonymous/7a96aaea08d131e3edb3 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#[derive(Debug)]
struct Pair(i32,i32);
fn eat(y:&mut Pair) { y.0 = 1; y.1 = 2}
//fn replace(y:&mut Pair) { y = Pair(1,2)} // no? why not?
fn replace(y:&mut Pair) { let Pair(x,z) = Pair(1,2); y.0 = x; y.1 = z}
fn main(){
let mut p = Pair(5,6);
let mut q = Pair(5,6);
eat(&mut p);
replace(&mut q);
//println!("{:?}", x);
println!("{:?}", p);
println!("{:?}", q);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment