If you make a struct derive the Copy
trait then Rust is going to make y
as a copy of x
in the code below, as opposed to moving from x
to y
otherwise:
#[derive(Debug, Copy, Clone)]
struct Foo;
let x = Foo;
let y = x;
If I were in C++ I'd say that Copy
somehow makes Foo
implement the =
operator in a way that it copies the entire object on the right side.
In Rust, is it simply implemented as a rule in the compiler? When the compiler finds let y=x
it simply checks if the Copy trait is derived or not and decides if copy or moves?
I'm intersted in Rust internals so I can understand the language better. This information can't be found on tutorials.