← Back to archive

Stdle #171 · option · 2026-11-24

What does this Rust snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

fn main() {
let x = Some(4);
let r = x.and_then(|n| if n > 2 { Some(n * 10) }
else { None });
println!("{:?}", r);
let y = Some(1);
println!("{:?}", y.and_then(|n|
if n > 2 { Some(n) } else { None }));
}
Option
2 lines
4 attempts left

Answer & explanation