← All Exercises
Explicit Lifetime Annotations
advancedrust
Background
Lifetimes ensure references remain valid, preventing dangling pointers at compile time.
Problem
Write a function that returns a reference with explicit lifetime annotations to satisfy the borrow checker.
Input
References with lifetimes
Output
Valid reference with correct lifetime
Sample tests
Sample 1
Input: longest("a", "ab")Expected: "ab"
Your solution
Learning objective
Master Rust lifetimes and reference validity