pounder_test/dsp/src/accu.rs

21 lines
395 B
Rust
Raw Normal View History

#[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 }
}
}
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)
}
}