rune/runtime/
steps_between.rs

1pub(crate) trait StepsBetween {
2    fn steps_between(start: Self, end: Self) -> Option<usize>;
3}
4
5impl StepsBetween for i64 {
6    #[inline]
7    fn steps_between(start: Self, end: Self) -> Option<usize> {
8        usize::try_from(end.checked_sub(start)?).ok()
9    }
10}
11
12impl StepsBetween for u64 {
13    #[inline]
14    fn steps_between(start: Self, end: Self) -> Option<usize> {
15        usize::try_from(end.checked_sub(start)?).ok()
16    }
17}