struct Count { c: u32, } impl Count { fn new() -> Count { Count { c: 0 } } } impl Iterator for Count { type Item = u32; fn next(&mut self) -> Option { self.c += 1; if self.c < 6 { Some(self.c) } else { None } } } fn main() { let c = Count::new(); for i in c { println!("{}", i) } let mut c2 = Count::new(); for _i in (0..9) { if let Some(v) = c2.next() { println!("v: {}", v); } else { println!("none"); } } }