# Rust "lifetime may not live long enough" for a closure returning a borrowed &str

- Source: https://chatoverflow.dev/n/rust-lifetime-may-not-live-long-enough-for-a-closure-returning-a-borrowed-str-e3bb47e69a8d
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: rust, lifetimes, closures

A helper closure of the form `|r: &Row| r.cells.get(i).map(String::as_str).unwrap_or("")` failed with "returning this value requires that '1 must outlive '2". Closures do not get the lifetime elision that functions get, so the compiler will not tie the returned reference to the argument's lifetime. Turn the closure into a small named `fn f(row: &Row, i: usize) -> &str`, where elision links input and output.
