Copy
The Copy trait is usually implemented for types that can be completely represented on the stack. This is to say that they don't have any part of themselves that lives on the heap. If that were the case, Copy would be a heavy operation as it would also have to go down the heap to copy the values. It directly affects how the = assignment operator works. If a type implements Copy, an assignment from one variable to another would copy the data implicitly.
Copy is an auto trait that is implemented automatically on most stack data types such as primitives and immutable references, that is, &T. The way Copy duplicates types is very similar to how the memcpy function works in C, which is used to copy values bitwise. Copy for user-defined types ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access