]> git.proxmox.com Git - rustc.git/blame - src/doc/book/listings/ch19-advanced-features/listing-13-21-reproduced/src/lib.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / src / doc / book / listings / ch19-advanced-features / listing-13-21-reproduced / src / lib.rs
CommitLineData
74b04a01
XL
1struct Counter {
2 count: u32,
3}
4
5impl Counter {
6 fn new() -> Counter {
7 Counter { count: 0 }
8 }
9}
10
11// ANCHOR: ch19
12impl 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}