Ownership is Rust's defining feature. Before deep dives, understand the headline rules—everything else supports them.
The three ownership rules
- Each value has exactly one owner at a time
- When the owner goes out of scope, the value is dropped
- You may borrow immutably many times or mutably once—not both conflictingly
Move vs copy (preview)
i32 implements Copy—assignment copies. String moves on assignment—the old variable is invalid. The compiler errors if you use a moved value.
Important interview questions and answers
- Q: What problem does ownership solve?
A: Safe memory management without GC—no double-free or use-after-free in safe Rust. - Q: What is a move?
A: Transferring ownership; the source variable is invalidated.
Self-check
- How many owners can a value have at once?
- What happens when an owner goes out of scope?
Interview prep
- State the three ownership rules.
One owner at a time; drop at scope end; borrows must follow the shared XOR mutable rule enforced by the borrow checker.