面试题答案
一键面试struct Counter {
current: i32,
max: i32,
}
impl Iterator for Counter {
type Item = i32;
fn next(&mut self) -> Option<Self::Item> {
if self.current <= self.max {
let result = Some(self.current);
self.current += 1;
result
} else {
None
}
}
}