1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::ops::{Add, Range};
#[derive(Clone)]
pub struct StepUp<T> {
next: T,
end: T,
ammount: T
}
impl <T> Iterator for StepUp<T> where
T: Add<T, Output = T> + PartialOrd + Copy {
type Item = T;
#[inline]
fn next(&mut self) -> Option<T> {
if self.next < self.end {
let n = self.next;
self.next = self.next + self.ammount;
Some(n)
} else {
None
}
}
}
pub trait RangeExt<T> {
fn step_up(self, ammount: T) -> StepUp<T>;
}
impl <T> RangeExt<T> for Range<T> where
T: Add<T, Output = T> + PartialOrd + Copy {
fn step_up(self, ammount: T) -> StepUp<T> {
StepUp {
next: self.start,
end: self.end,
ammount: ammount
}
}
}