3 ms·
You can't manually implement the `Copy` trait?
by echelon 10y ago
You can't manually implement the `Copy` trait?
- Manishearth 10y agoThat makes a type copyable, but does not allow you to insert arbitrary code that must be executed during a copy.
- hornetblack 10y agoKinda but: trait Copy: Clone {} Copy is nearly always done by memcpy/memmove. When Copy is invoked it won't use the `Clone::clone` method: https://is.gd/2hMyNP https://is.gd/2hMyNP. i.e. Clone is always explicit. Added: Essentially Copy is the same as a move, but the original value is still valid.
- masklinn 10y agoYou can but it has no user-defined methods related to it, it's just a marker trait. Move and copy are both straight memcpy, the difference is whether the source remains valid afterwards, not what operation is performed.