Skip to main content

libspecr/int/
step.rs

1use crate::int::*;
2
3use std::iter::Step;
4
5impl Step for Int {
6    fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
7        match (*end - *start).try_to_usize() {
8            Some(diff) => (diff, Some(diff)),
9            None => (usize::MAX, None),
10        }
11    }
12
13    fn forward_checked(start: Self, count: usize) -> Option<Self> {
14        Some(start + count)
15    }
16
17    fn backward_checked(start: Self, count: usize) -> Option<Self> {
18        Some(start - count)
19    }
20}