SS
Size: a a a
SS
P
SS
P
P
ФА
ФА
ФА
SS
struct Range {
current: i32,
last: i32,
step: i32,
}
impl Range {
fn new(current: i32, last: i32, step: i32) -> Self {
Self { current, last, step }
}
}
impl Iterator for Range {
type Item = i32;
fn next(&mut self) -> Option<Item> {
self.current += self.step;
if self.current >= self.last {
None
} else {
Some(self.current)
}
}
}
fn main() {
let list: Vec<_> = Range::new(0, 10, 2).map(|num| num * 2).collect();
println!("{:?}", list); // [2, 4, 6, 8]
}
P
SS
ФА
P
P
ФА
SS
ФА
ФА