Skip to main content

Lifetimes

Draft

This note is in progress.

TL;DR Lifetimes are the borrow checker's way of tracking how long a reference is valid. In most cases they're inferred. You write them explicitly when the compiler can't figure out the relationship between input and output reference lifetimes.

Planned Coverage

  • Lifetime elision rules
  • Named lifetimes ('a) in function signatures
  • Lifetime bounds on structs
  • 'static lifetime
  • Higher-rank trait bounds (HRTB) — for<'a>
Ownership ModelOwnership rules that lifetimes enforce Borrowing & ReferencesThe borrow rules that lifetimes annotate