How to Use the Return Keyword vs Implicit Return in Rust

Use `return` for immediate early exits and implicit return for the final expression at the end of a Rust function.

Use the return keyword to exit a function immediately from any point, and rely on implicit return by placing the final expression at the end of the function body without a semicolon. Use return for early exits in control flow, such as inside loops or conditionals, and use implicit return for the standard flow of the function.

fn first_word(s: &str) -> &str {
    let bytes = s.as_bytes();
    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[0..i]; // Explicit return exits early
        }
    }
    &s[..] // Implicit return is the last expression
}