How to Chain Iterators in Rust

Chain iterators in Rust by calling adapter methods like filter and map sequentially on an iterator, finishing with a consumer method.

Chain iterators in Rust by calling iterator adapter methods directly on the result of the previous one, ending with a consumer method like collect or for_each.

let numbers = vec![1, 2, 3, 4, 5];
let doubled: Vec<i32> = numbers
    .iter()
    .filter(|&&x| x % 2 == 0)
    .map(|&x| x * 2)
    .collect();