Skip to main content
InterviewHubPRO
Section Overview
Q12

Question 12 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

24%
Rust Systems & Tokio (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What are the Lifetime Elision Rules?

senior LevelSystem Design

In Simple Words: In common code patterns, the Rust compiler infers lifetimes automatically without explicit annotations:

  1. Each input reference parameter gets its own distinct lifetime parameter (fn foo<'a, 'b>(x: &'a str, y: &'b str)).
  2. If there is exactly one input reference, its lifetime is assigned to all output references.
  3. If there are multiple input references, but one of them is &self or &mut self (a method), the lifetime of self is assigned to all output references.