fn main() {
struct Foo {
c: Vec<u32>,
}
let f = Foo {
c: Vec::new(),
};
let d = f.c; // this works!
//println!("f.c {:?}", f.c); // f.c is moved
println!("d {:?}", d);
let vf = vec![Foo {
c: vec![0, 1, 2],
}];
let e = vf[0].c; // isn't this the same??? works if &vf[0].c
println!("vf[0].c {:?}", vf[0].c);
println!("e {:?}", e);
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of index of `Vec<Foo>`
--> src/main.rs:14:13
|
14 | let e = vf[0].c; // isn't this the same??? works if &vf[0].c
| ^^^^^^^ move occurs because value has type `Vec<u32>`, which does not implement the `Copy` trait
|
help: consider borrowing here
|
14 | let e = &vf[0].c; // isn't this the same??? works if &vf[0].c
| +
help: consider cloning the value if the performance cost is acceptable
|
14 | let e = vf[0].c.clone(); // isn't this the same??? works if &vf[0].c
| ++++++++
For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` (bin "playground") due to 1 previous error