Ownership and borrowing, gently
The mental model that makes Rust click — explained without the jargon.
Table of Contents
Most Rust confusion is really ownership confusion. Get this one idea straight and the borrow checker turns from enemy to proofreader.
The idea
Every value has exactly one owner. When the owner goes out of scope, the value is dropped. You can lend a value out — immutably to many, or mutably to exactly one — but lending never transfers ownership.
fn main() {
let owner = String::from("updeta");
let read = &owner; // immutable borrow
println!("{read}");
let mut owned = String::from("hi");
owned.push_str("!"); // owner mutates directly
takes_ownership(owned); // moves: owner no longer valid
}
fn takes_ownership(s: String) {
println!("{s}");
}
Why it matters
No use-after-free, no dangling pointers, no data races — all checked at compile time, all with zero runtime cost.
Practical tips
- Start with borrows (
&T); move (T) only when you must Stringvs&str: own the text, or point into text someone else owns- When the compiler complains, it is describing a real lifecycle problem — read the message, it’s good now
Part 2 covers traits and generics: how shared behavior works when there are no classes.