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

An iterator chain `v.iter().filter(...).map(...).sum()` over a slice is compiled with optimizations. What is the key compiler mechanism that lets this match a hand-written loop with no per-element indirection?

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