Copy
特質を持たない変数を関数に渡すと、所有権の移動が発生し、関数に渡した変数は使用不可能になる。
fn main() {
let s = String::from("hello");
test(s);
println!("{}", s); //error
/*
error[E0382]: borrow of moved value: `s`
--> src\main.rs:4:20
|
2 | let s = String::from("hello");
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait
3 | test(s);
| - value moved here
4 | println!("{}", s); //error
| ^ value borrowed here after move
*/
}
fn test(s:String) {
println!("{}", s); //hello
}