← Back to archive

Stdle #132 · closures · 2026-10-16

What does this Rust snippet output?

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

fn counter() -> impl FnMut() -> i32 {
let mut n = 0;
move || { n += 1; n }
}
fn main() {
let mut c = counter();
println!("{} {} {}", c(), c(), c());
}
Closures
4 attempts left

Answer & explanation