fn foo() {

let x = 7i;

let y = x; // x is copied

println!("x is {}", x); // OK



let x = box 7i;

let y = x; // x is moved

//println!("x is {}", x); // error: use of moved value: `x`

}

enum Enum1 {

Var1,

Var2,

Var3

}



fn foo(x: &Enum1) {

match *x { // Option 1: deref here.

Var1 => {}

Var2 => {}

Var3 => {}

}



match x {

// Option 2: 'deref' in every arm.

&Var1 => {}

&Var2 => {}

&Var3 => {}

}

}

enum Enum2 {

// Box has a destructor so Enum2 has move semantics.

Var1(Box<int>),

Var2,

Var3

}



fn foo(x: &Enum2) {

match *x {

// We're ignoring nested data, so this is OK

Var1(..) => {}

// No change to the other arms.

Var2 => {}

Var3 => {}

}



match x {

// We're ignoring nested data, so this is OK

&Var1(..) => {}

// No change to the other arms.

&Var2 => {}

&Var3 => {}

}

}

match *x {

Var1(y) => {}

_ => {}

}

match x {

&Var1(y) => {}

_ => {}

}

fn bar(x: &Enum2, y: &Enum2) {

// Error: x and y are being moved.

// match (*x, *y) {

// (Var2, _) => {}

// _ => {}

// }



// OK.

match (x, y) {

(&Var2, _) => {}

_ => {}

}

}

fn baz(x: Enum2) {

match x {

Var1(y) => {}

_ => {}

}

}