diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs index c90cf2c2ee..bb3741339c 100644 --- a/core/src/utils/mod.rs +++ b/core/src/utils/mod.rs @@ -89,7 +89,14 @@ where I: Clone + Into, { match bound { - Bound::Excluded(i) => i.clone().into().saturating_sub(1), + Bound::Excluded(i) => { + let val = i.clone().into(); + if is_start { + val.saturating_add(1) + } else { + val.saturating_sub(1) + } + }, Bound::Included(i) => i.clone().into(), Bound::Unbounded => { if is_start { @@ -195,6 +202,17 @@ mod tests { } } + #[test] + fn test_bound_into_included_u64() { + let val = 10u64; + assert_eq!(bound_into_included_u64(Bound::Included(&val), true), 10); + assert_eq!(bound_into_included_u64(Bound::Included(&val), false), 10); + assert_eq!(bound_into_included_u64(Bound::Excluded(&val), true), 11); + assert_eq!(bound_into_included_u64(Bound::Excluded(&val), false), 9); + assert_eq!(bound_into_included_u64(Bound::<&u64>::Unbounded, true), 0); + assert_eq!(bound_into_included_u64(Bound::<&u64>::Unbounded, false), u64::MAX); + } + #[test] #[should_panic] fn debug_assert_is_checked() {