Skip to content

Relax RangeMap::overlapping to allow infinite ranges as query? #97

@MultisampledNight

Description

@MultisampledNight

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 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions