let x: &mut i32 = &mut 5;
let y = &mut 7;
println!("x: {}, y: {}", x, y);
let x_pin = Pin::new(x);
let y_pin: Pin<&mut i32> = Pin::new(y);
mem::swap(x_pin.get_mut(), y_pin.get_mut());
println!("x: {}, y: {}", x, y);
got following error:
error[E0382]: borrow of moved value: x
--> 16_pin.rs:37:27
|
24 | let x: &mut i32 = &mut 5;
| - move occurs because x
has type &mut i32
, which does not implement the Copy
trait
...
30 | let x_pin = Pin::new(x);
| - value moved here
...
37 | println!("x: {}, y: {}", x, y);
| ^ value borrowed here after move
My question is why 'y' can access but 'x' cannot?