How can I zip more than two iterators?

You can use the izip!() macro from the crate itertools, which implements this for arbitrary many iterators:

use itertools::izip;

fn main() {

    let a = [1, 2, 3];
    let b = [4, 5, 6];
    let c = [7, 8, 9];

    // izip!() accepts iterators and/or values with IntoIterator.
    for (x, y, z) in izip!(&a, &b, &c) {

    }
}

You would have to add a dependency on itertools in Cargo.toml, use whatever version is the latest. Example:

[dependencies]
itertools = "0.8"

Leave a Comment