]>
Commit | Line | Data |
---|---|---|
74b04a01 XL |
1 | struct Counter { |
2 | count: u32, | |
3 | } | |
4 | ||
5 | impl Counter { | |
6 | fn new() -> Counter { | |
7 | Counter { count: 0 } | |
8 | } | |
9 | } | |
10 | ||
11 | // ANCHOR: ch19 | |
12 | impl Iterator for Counter { | |
13 | type Item = u32; | |
14 | ||
15 | fn next(&mut self) -> Option<Self::Item> { | |
16 | // --snip-- | |
17 | // ANCHOR_END: ch19 | |
18 | if self.count < 5 { | |
19 | self.count += 1; | |
20 | Some(self.count) | |
21 | } else { | |
22 | None | |
23 | } | |
24 | } | |
25 | } |