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
- Why Lifetimes
- Lifetime Annotations
- Lifetimes in Structs
- Elision Rules