0Pricing
Learn Rust Coding · Lesson

Lifetime Annotations

Naming lifetimes.

Naming a Lifetime

A lifetime annotation is a name starting with an apostrophe, like 'a. It does not change how long anything lives; it describes relationships between the lifetimes of references.

Where Annotations Go

You declare lifetime parameters in angle brackets after the function name, then use them on the reference types, just like generic type parameters.

Syntax: fn name<'a>(x: &'a T) -> &'a T.

All lessons in this course

  1. Why Lifetimes
  2. Lifetime Annotations
  3. Lifetimes in Structs
  4. Elision Rules
← Back to Learn Rust Coding