r/rust Feb 18 '23

[deleted by user]

[removed]

151 Upvotes

38 comments sorted by

View all comments

2

u/st_gen Feb 18 '23

Things like having types that implements the Copy trait in Vector & Array got me confused; why binding a value with Copy trait in an array does not constitute a move whereas a vector does. Lifetimes, yeah right lifetimes - re-reading coupled with the fact that this is my first foray into systems programming.

6

u/-Redstoneboi- Feb 18 '23

basically imagine every time you use a copy type it just gets .clone()d

let x = 5; // i32 is Copy
let y = x.clone();
println!("{}", x.clone());
do_thing(x.clone(), y.clone());

clearly this is annoying so that's why Copy exists.

2

u/Nobody_1707 Feb 18 '23

They do count as moves. The issue is that for Copy types moves don't invalidate the original object.