Namara

Code daily. Without assist.

2026-08-21

first_word.rs

fn first_word(s: &str) -> &str {
    // write this
}

Implement first_word: return the first whitespace-separated word of s, or the whole string if there's no whitespace.

Reference
fn first_word(s: &str) -> &str {
    s.split_whitespace().next().unwrap_or("")
}

The returned slice borrows from s, which is why no explicit lifetime is needed — there's only one input reference for the elided output lifetime to match.