Rust Ownership and the Copy trait


Some Rust types implement the Copy trait. Types that are Copy can be moved without owning the value in question. This is because the contents of the value can simply be copied byte-for-byte in memory to produce a new, identical value. Most primitives in Rust (bool, usize, f64, etc.) are Copy.

let x: isize = 42;
let xr = &x;
let y = *xr; // OK, because isize is Copy
// both x and y are owned here

Notably, Vec and String are not Copy:

let x = Vec::new();
let xr = &x;
let y = *xr; // ERROR, cannot move out of borrowed content