← Back to Notes
Learning Rust: Ownership
Ownership is Rust's most unique feature. It enables memory safety without a garbage collector.
The Rules
- Each value in Rust has a variable that's called its owner.
- There can only be one owner at a time.
- When the owner goes out of scope, the value will be dropped.
{
let s = String::from("hello"); // s is valid from this point forward
// do stuff with s
} // this scope is over, and s is no longer valid