You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a RangeSet that holds ranges of datetimes to denote when an event is happening.
I'd like to query for a relative index after some time point, e.g. "get the 3rd event after 2024-10-04".
This requires specifying a range with an unbounded side if the index is not known ahead-of-time.
At a first glance, RangeSet::overlapping is perfect for this! However, it only accepts finite ranges, not infinite ones.
Intended solution
Replace the R: Borrow<Range<T>> bound in Range{,Inclusive}{Map,Set}::overlapping with R: RangeBounds<T>.
Possible workaround
Call RangeSet::overlapping with the extreme value the key can hold as a replacement for the unbounded side. In effect, for example:
Replace upper unbound with maximum excluded: set.overlapping(4..) → set.overlapping(4..i32::MAX).
Replace lower unbound with minimum included: set.overlapping(..4) → set.overlapping(i32::MIN..4)
This is also the workaround I'll head to for now, and tbh I can't think of a case where it wouldn't work (but i only thought like 3 seconds about it sooo there might be something i missed).
(Sidenote: thanks for the wonderful library! :3)
The text was updated successfully, but these errors were encountered:
The workaround of using the maximum value is the correct call in my opinion. I say this after trying out the RangeBounds idea you mentioned a couple of years ago, I made a PR here but then made my own crate for it which used RangeBounds but then eventually I found that it was unnecessary complexity and that just using the maximum values when needed is perfectly fine for all situations.
Problem
I have a
RangeSet
that holds ranges of datetimes to denote when an event is happening.I'd like to query for a relative index after some time point, e.g. "get the 3rd event after
2024-10-04
".This requires specifying a range with an unbounded side if the index is not known ahead-of-time.
At a first glance,
RangeSet::overlapping
is perfect for this! However, it only accepts finite ranges, not infinite ones.Intended solution
Replace the
R: Borrow<Range<T>>
bound inRange{,Inclusive}{Map,Set}::overlapping
withR: RangeBounds<T>
.Possible workaround
Call
RangeSet::overlapping
with the extreme value the key can hold as a replacement for the unbounded side. In effect, for example:set.overlapping(4..)
→set.overlapping(4..i32::MAX)
.set.overlapping(..4)
→set.overlapping(i32::MIN..4)
This is also the workaround I'll head to for now, and tbh I can't think of a case where it wouldn't work (but i only thought like 3 seconds about it sooo there might be something i missed).
(Sidenote: thanks for the wonderful library! :3)
The text was updated successfully, but these errors were encountered: