Lifetime
A lifetime is the region of code where a reference is valid; Rust uses lifetime annotations to ensure references never outlive the data they borrow.
Purpose
Prevent dangling references at compile time — the core of Rust's borrow checker.
Mechanism
Annotation 'a: the reference is valid for lifetime 'a. The compiler checks that the referenced data lives at least as long as the reference. The 'static lifetime spans the whole program. Elision rules infer common patterns automatically.
Use cases
- Rust programming
- Reference safety
- Borrow checking