0Pricing
Learn Rust Coding · Lesson

Elision Rules

When lifetimes are inferred.

Lifetimes You Do Not Write

Many functions take and return references without any lifetime annotations, yet they compile. That is because of lifetime elision: the compiler infers obvious lifetimes for you.

Elision Is Just a Shortcut

Elision does not remove lifetimes; the compiler still fills them in behind the scenes using a few deterministic rules. When the rules cover your case, you can omit the annotations.

All lessons in this course

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