Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustzero-cost abstraction in codegenSingle-choice MCQ

A library author wraps a slice iteration in `iter().map(closure).filter(closure).sum()`. Why is this considered a zero-cost abstraction in the generated machine code (release build)?

fn sum_evens(v: &[u32]) -> u32 { v.iter().filter(|&&x| x % 2 == 0).map(|&x| x * 2).sum() }