Last active: 2 years ago
struct Count {
pub value: u32,
inter_value: u32,
}
impl Count {
fn new(value: u32) -> Self {
Self {
value,
inter_value: 0,
}
}
}
impl Iterator for Count {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.inter_value < self.value {
self.inter_value += 1;
Some(self.inter_value)
} else {
None
}
}
}
fn main() {
let counter = Count::new(5);
counter.for_each(|v| println!("{}", v));
}