Rust and Cargo 1 · Code patterns
Transform a collection
Chain iterator adapters, then collect the result.
let squares: Vec<u32> = (1..=5).map(|n| n * n).filter(|n| n % 2 == 1).collect();
Official Rust and Cargo 1 documentation
Rust and Cargo 1 · Code patterns
Chain iterator adapters, then collect the result.
let squares: Vec<u32> = (1..=5).map(|n| n * n).filter(|n| n % 2 == 1).collect();
Official Rust and Cargo 1 documentation
Was this page helpful?