An infinite iterator has no end: it can keep producing items indefinitely. Rust's .cycle() repeats an iterator forever, while an open range such as 0.. never stops. section 9.1.4
Use an infinite iterator with a finite consumer such as .zip(), or limit it with .take(). The infinite side does not force the result to be infinite when another iterator or operation sets a boundary. section 9.1.4
Alternating labels
Cycling ["even", "odd"] produces labels forever, but zipping it with 0..=5 creates only six pairs: even, odd, even, odd, even, odd. section 9.1.4
fn main() {
let even_odd_iter = ["even", "odd"].into_iter().cycle(); #1
let even_odd_vec: Vec<(i32, &str)> = (0..=5)
.zip(even_odd_iter)
.collect();
println!("{:?}", even_odd_vec);
}
Run the example to see an infinite cycling iterator safely paired with a finite range. section 9.1.4
