Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ where
I: Clone + Into<u64>,
{
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 {
Expand Down Expand Up @@ -195,6 +202,17 @@ mod tests {
}
}

#[test]
fn test_bound_into_included_u64() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At u64::MAX, the new addition saturates back to u64::MAX, so an excluded start becomes a range containing that value instead of an empty range. Excluding 0 as an end has the same problem. Could this return Option or Result to represent these empty bounds and cover both endpoints here?

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() {
Expand Down
Loading