所有權和複製特徵
一些 Rust 型別實現了 Copy 特性。可以在不擁有相關值的情況下移動 Copy 的型別。這是因為值的內容可以簡單地在記憶體中逐位元組複製,以產生新的相同值。Rust(bool,usize,f64 等)中的大多數原始人都是 Copy。
let x: isize = 42;
let xr = &x;
let y = *xr; // OK, because isize is Copy
// both x and y are owned here
值得注意的是,Vec 和 String 不是 Copy:
let x = Vec::new();
let xr = &x;
let y = *xr; // ERROR, cannot move out of borrowed content