1
Ownership
Each value in Rust has a single owner. When the owner goes out of scope, the value is dropped. This is the foundation — the first rule of the quest.
let s1 = String::from("hello");
let s2 = s1; // s1 is moved
// s1 is no longer valid
fn greet(name: &String) {
println!("Hello, {}", name);
}
let s = String::from("world");
greet(&s); // borrowing s
2
Borrowing
References allow you to refer to a value without taking ownership. Immutable references are unlimited; mutable references are exclusive. The borrow checker enforces safety.
3
Lifetimes
Every reference has a lifetime — the scope for which that reference is valid. Rust's lifetime annotations ensure references never outlive the data they point to. The quest deepens.
fn longest<'a>(x: &'a str, y: &'a str)
-> &'a str {
if x.len() > y.len() { x }
else { y }
}
match result {
Ok(val) => val,
Err(e) => return Err(e),
}
4
Error Handling
No exceptions. No nulls. Rust uses Result and Option types to make error handling explicit and safe. Every path is accounted for. The quest demands precision.