How to Use map, filter, and collect in Rust

Transform, filter, and collect Rust data using iterator methods in a single chain.

Use .map() to transform items, .filter() to keep items matching a condition, and .collect() to gather results into a collection like a Vec. These methods are chained on iterators to process data functionally.

fn main() {
    let numbers = vec![1, 2, 3, 4, 5];
    let result: Vec<u32> = numbers
        .iter()
        .filter(|&&n| n % 2 == 0)
        .map(|&n| n * 10)
        .collect();
    println!("{:?}", result); // [20, 40]
}