2 ms·
By structuring code appropriately - for example, in a GC-based system you can create new objects from anywhere, but in Rust it tends to make more sense to follo
by antonvs 3y ago
By structuring code appropriately - for example, in a GC-based system you can create new objects from anywhere, but in Rust it tends to make more sense to follow a RAII-style model where you take advantage of scope to simplify lifetime management.
Also, by knowing when and how to use wrappers like RC, Arc, RefCell, Box, etc., and by knowing when and how to use lifetime annotations.
As for copying, you learn when to move, when to copy, when to clone, and when to implement the relevant traits on your types.
It's really not that different from working in a language like C or C++, except that the compiler ensures that you're not making any mistakes.