Start with the idea
Types that are cheap and have no destructor can be Copy, so assigning them leaves the original usable. Everything that owns a heap allocation is not Copy, and duplicating it means calling .clone() explicitly — the cost is visible in the source rather than hidden in an assignment.
Copy means a value can be duplicated by copying its bits, with no visible method call. Primitive integers and many small plain-data structs qualify. A type with a destructor cannot be Copy, because two implicit copies would both try to perform cleanup. String owns a heap allocation and therefore moves on ordinary assignment. Clone is different: it is an explicit operation, and its cost depends on the type. Cloning a String duplicates its bytes into a new buffer.
In the sample, a and b are separate integers after let b = a, so both print.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.