← Back to archive

Stdle #157 · closures · 2026-11-10

What does this Rust snippet output?

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

fn make_summer(v: Vec<i32>) -> impl Fn() -> i32 {
move || v.iter().sum()
}
fn main() {
let f = make_summer(vec![1, 2, 3, 4]);
println!("{} {}", f(), f());
}
Closures
4 attempts left

Answer & explanation