Fundamentals42 / 42
Up next

Option and match

fn first_even(nums: &[i32]) -> Option<i32> {
    nums.iter().copied().find(|n| n % 2 == 0)
}

fn main() {
    match first_even(&[1, 3, 6, 7]) {
        Some(n) => println!("found {n}"),
        None => println!("none"),
    }
}
What you're solving

returning Option and matching it