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

More code patterns commands

All code patterns commands · Rust and Cargo 1 cheatsheet

Was this page helpful?