iteration using custom element
If you have one item, use iter::once.
If you have multiple items, use iter::repeatin conjunction with Iterator::take.
to start iteration with
Use Iterator::chain.
Combine together:
use std::iter;
fn main() {
let some_iterator = 1..10;
let start_with = iter::repeat(42).take(5);
let together = start_with.chain(some_iterator);
for i in together {
println!("{}", i);
}
}
source
share