// Created on savesnippets.com · https://savesnippets.com/CZExuwt5x9w015 fn main() { let names = vec!["Alice", "Bob", "Cara"]; let ages = vec![30, 25, 35]; // zip — pair two iterators (stops at the shorter one) let paired: Vec<(&&str, &i32)> = names.iter().zip(ages.iter()).collect(); for (n, a) in &paired { println!("{n} is {a}"); } // enumerate — get (index, value) pairs for (i, name) in names.iter().enumerate() { println!("{i}: {name}"); } // chain — concatenate two iterators let a = vec![1, 2, 3]; let b = vec![4, 5, 6]; let all: Vec = a.iter().chain(b.iter()).copied().collect(); println!("{all:?}"); // [1, 2, 3, 4, 5, 6] // unzip — split a Vec<(A,B)> into (Vec, Vec) let pairs = vec![(1, 'a'), (2, 'b'), (3, 'c')]; let (ints, chars): (Vec, Vec) = pairs.into_iter().unzip(); println!("{ints:?} {chars:?}"); }