Ownership is how Rust achieves memory safety without a Garbage Collector. Every value follows three simple rules:
- Each value in Rust has a single owner (a variable).
- There can only be one owner at a time.
- When the owner goes out of scope (at the closing
}), the value is automatically dropped and its heap memory is freed!
ADVERTISEMENT