use std::error::Error;
struct Counter {
count: u32,
}
impl Counter {
fn new() -> Counter {
Counter { count: 0 }
}
}
impl Iterator for Counter {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.count < 5 {
self.count += 1;
Some(self.count)
} else {
None
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
let list = vec![9, 5, 3, 4, 8];
println!("{:?}", list);
let c = Counter::new().skip(2).zip(list).map(|(x, y)| x * y);
for i in c {
println!("{:?}", i)
}
Ok(())
}