3 ms·
I think you are misunderstanding what Copy means, and perhaps confusing it with Clone. A type being Copy has no effect on what machine code is emitted when you
by School-Cotton 1y ago
I think you are misunderstanding what Copy means, and perhaps confusing it with Clone. A type being Copy has no effect on what machine code is emitted when you write "x = y". In either case, it is moved by copying the bit pattern.
The only thing that changes if the type is Copy is that after executing that line, you are still allowed to use y.
- littlestymaar 1y agoI'm not misunderstanding. Ore confusing the two. Copy: Clone. Yes when an item is Copy-ed, you are still allowed to use it, but it means that you now have two independent copies of the same thing, and you may edit one, then use the other, and be surprised that it hasn't been updated. (When I briefly worked with Go, junior developers with mostly JavaScript or Python experience would fall into this trap all the time). And given that most languages nowadays have pointer semantics, having default copy types would lead to a very confusing situation: people would need to learn about value semantics AND about move semantics for objects with a destructor (including all collections). No thanks. Rust is already complex enough for beginners to grasp.
- School-Cotton 1y agoGot it. Indeed, I misunderstood your point. I agree with you now that you clarified.