Back to library

🦀Rust Lifetimes Explained

Stop reading `'a` as line noise and start reading it as scope arithmetic — one failing snippet at a time — until you can thread lifetimes through a small parser or iterator adapter without fighting the borrow checker.

Applied14 drops~2-week path · 5–8 min/daytechnology

Phase 1Scopes, References, and Why the Compiler Asks

See `'a` as scope duration, not decoration.

4 drops
  1. A lifetime is a scope the compiler can point at

    6 min

    A lifetime is a scope the compiler can point at

  2. References are just addresses with an expiration date

    6 min

    References are just addresses with an expiration date

  3. Lifetime annotations exist when inference can't guess

    6 min

    Lifetime annotations exist when inference can't guess

  4. The borrow checker is a conservative deadline solver

    7 min

    The borrow checker is a conservative deadline solver

Phase 2Reading and Writing Lifetime Annotations

Fix real compiler errors by annotating functions.

5 drops
  1. Fix compiler errors with the smallest annotation that works

    7 min

    Fix compiler errors with the smallest annotation that works

  2. Three elision rules cover the common cases silently

    7 min

    Three elision rules cover the common cases silently

  3. `'static` means the reference lives forever — literally

    7 min

    `'static` means the reference lives forever — literally

  4. Mutable references are exclusive access for a duration

    7 min

    Mutable references are exclusive access for a duration

  5. Longer lifetimes flow into shorter ones — not the other way

    8 min

    Longer lifetimes flow into shorter ones — not the other way

Phase 3Lifetimes Across Structs, Traits, and Bounds

Wire lifetimes through structs, traits, and bounds.

4 drops
  1. A struct that holds a reference must name the lifetime

    8 min

    A struct that holds a reference must name the lifetime

  2. Every impl on a lifetime-parameterized struct declares the lifetime twice

    8 min

    Every impl on a lifetime-parameterized struct declares the lifetime twice

  3. The `T: 'a` bound says T has no references shorter than `'a`

    8 min

    Generic bounds like `T: 'a` mean T doesn't contain any reference shorter than `'a`

  4. Trait bounds and lifetime bounds compose orthogonally

    8 min

    Trait bounds and lifetime bounds compose orthogonally

Phase 4Build a Zero-Copy Parser

Build a zero-copy parser that threads `'a` through.

1 drop
  1. Thread `'input` through a tiny zero-copy parser

    22 min

    Build a struct that parses a string without cloning a byte

Frequently asked questions

What does the `'a` in Rust actually mean?
This is covered in the “Rust Lifetimes Explained” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why does the Rust compiler need lifetime annotations?
This is covered in the “Rust Lifetimes Explained” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
When do I need to add lifetimes to a struct?
This is covered in the “Rust Lifetimes Explained” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What is the lifetime elision rule in Rust?
This is covered in the “Rust Lifetimes Explained” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
How are lifetimes different from ownership and borrowing?
This is covered in the “Rust Lifetimes Explained” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.