Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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