mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
414 B
26 lines
414 B
struct Counter {
|
|
count: u32,
|
|
}
|
|
|
|
impl Counter {
|
|
fn new() -> Counter {
|
|
Counter { count: 0 }
|
|
}
|
|
}
|
|
|
|
// ANCHOR: ch19
|
|
impl Iterator for Counter {
|
|
type Item = u32;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
// --snip--
|
|
// ANCHOR_END: ch19
|
|
if self.count < 5 {
|
|
self.count += 1;
|
|
Some(self.count)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|