2021-02-14 14:47:55 +01:00
|
|
|
#![crate_name = "foo"]
|
|
|
|
|
|
|
|
use std::iter::Iterator;
|
|
|
|
|
|
|
|
// @has foo/struct.Odd.html
|
2021-04-23 22:15:57 +02:00
|
|
|
// @has - '//div[@id="method.new"]//span[@class="notable-traits"]//code/span' 'impl Iterator for Odd'
|
2021-02-14 14:47:55 +01:00
|
|
|
pub struct Odd {
|
|
|
|
current: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Odd {
|
|
|
|
pub fn new() -> Odd {
|
|
|
|
Odd { current: 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for Odd {
|
|
|
|
type Item = usize;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
self.current += 2;
|
|
|
|
Some(self.current - 2)
|
|
|
|
}
|
|
|
|
}
|