4 ms·
FWIW Rust has the Copy trait which lets you more or less do exactly what you’re asking with no pasting required.
by afavour 3y ago
FWIW Rust has the Copy trait which lets you more or less do exactly what you’re asking with no pasting required.
- imor80 3y agoCopy and Clone traits have different semantics. Copy is only for bitwise (and cheap) copies. Clone is for explicit, potentially expensive copies. Also what entails cloning differs from type to type. String, for example, needs to duplicate the pointed to string buffer in the heap, while Arc only increments a reference count.
- afavour 3y agoYes, I know. But in the context of what’s being described here someone getting started with Rust and wanting to avoid issues with lifetimes could very easily be using copy in the way the OP described clone.