← Back to archive

Stdle #81 · option · 2026-08-26

What does this Rust snippet output?

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

fn main() {
let x = Some(5);
let r = x.map_or_else(|| -1, |n| n + 1);
println!("{}", r);
let y: Option<i32> = None;
println!("{}", y.map_or_else(|| -1, |n| n + 1));
}
Option
2 lines
4 attempts left

Answer & explanation