quest

Sign in to start training

quest keeps your progress, streaks, and scores tied to your account — so you can pick up on any device.

Synced everywhere. Progress follows you across laptop and phone.
Streaks & stats. See your daily run and every score over time.
Your profile. A name and avatar for the work you do here.

We only use Google to sign you in and sync progress. No posting, no contacts — ever.

Core Beginner

04  Strings & slices

Two string types: String owns its text, &str borrows a view of it. Slice out the first word, then build a fresh String from a borrowed one.

Step 1 / 2

Return the &str slice up to the first space in first_word -- the whole string if there's no space.

Hints
  • s.find(' ') gives Option<usize> -- the index of the first space.
  • Slice up to it with &s[..i]; on None, the whole string is the word.
04_strings.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn first_word(s: &str) -> &str {
    match s.find(' ') {
        Some(i) => &s[..i],
        None => s,
    }
}