Error

"missing lifetime specifier" — How to Fix

Fix the missing lifetime specifier error by adding a lifetime parameter like 'a to both the input reference and the return type in your function signature.

Add an explicit lifetime parameter to the function signature to tell the compiler how long the returned reference is valid relative to the input.

fn first_word(s: &str) -> &str {
    // ... implementation
}

// Fix: Add 'a to both input and output
fn first_word<'a>(s: &'a str) -> &'a str {
    // ... implementation
}

The 'a lifetime parameter links the input s and the return value, ensuring the returned reference never outlives the string slice it points to.