2021-02-01 19:22:50 +08:00
|
|
|
#[derive(Copy, Clone, Default, PartialEq, Debug)]
|
|
|
|
pub struct Accu {
|
|
|
|
state: i32,
|
|
|
|
step: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Accu {
|
2021-02-01 19:37:44 +08:00
|
|
|
pub fn new(state: i32, step: i32) -> Self {
|
|
|
|
Self { state, step }
|
2021-02-01 19:22:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Iterator for Accu {
|
|
|
|
type Item = i32;
|
|
|
|
fn next(&mut self) -> Option<i32> {
|
|
|
|
let s = self.state;
|
|
|
|
self.state = self.state.wrapping_add(self.step);
|
|
|
|
Some(s)
|
|
|
|
}
|
|
|
|
}
|