use std::cmp::PartialOrd; use std::ops::AddAssign; pub struct Stepper { curr: T, step: T, stop: T, } impl Stepper { pub fn new(start: T, stop: T, step: T) -> Self { Stepper { curr: start, stop: stop, step: step, } } } impl Iterator for Stepper where T: AddAssign + Copy + PartialOrd, { type Item = T; fn next(&mut self) -> Option { if self.curr >= self.stop { return None; } let res = self.curr; self.curr += self.step; Some(res) } }