-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntoBounds::clamp
and RangeBounds::is_empty
#539
Comments
// you claimed: assert!(!(Excluded(1), Excluded(2)).is_empty());
//
// but, that's wrong (for indexes/integers),
// since there are no integers strictly between 1 and 2
assert_eq!(&"abcdef"[(Bound::Excluded(1), Bound::Excluded(2))], ""); |
We discussed this in today's @rust-lang/libs-api meeting. We'd like to see Separately from this ACP, we also had a mild interest in seeing a way to get back a Range type for an intersection of ranges, but we agreed that that would take a lot more API design and should not be made a part of this ACP. |
We would need to support Turning that into 2 steps by adding |
The idea was to restrict |
I thought the biggest use case was something like std::slice::range (which is why the ACP function name was |
If we were to add this alternative, realistically We could also use a |
Any kind of "intersect two ranges to get a range" mechanism is going to need a lot of API design. Let's not do that in the GitHub comments of a now-approved-and-closed ACP, and create a lot of noise for people who are looking for the status of the API this ACP proposed. For the API design of some future feature, may I suggest Zulip or IRLO or somewhere else? |
…ct, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
…ct, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
…ct, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
Rollup merge of rust-lang#137304 - pitaj:rangebounds-is_empty-intersect, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
…ct, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
…ct, r=ibraheemdev add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: rust-lang/libs-team#539 - Tracking issue for `is_empty`: rust-lang#137300 - Tracking issue for `IntoBounds`: rust-lang#136903
Proposal
Problem statement
Range types are essentially abstract sets, defined by a start and end point. A common operation on sets is calculating the intersection, and in practice this applies to ranges as well.
Having a generic way to tell if the result is empty is also useful.
Motivating examples or use cases
A custom slice type where indexing always succeeds
The examples from #277 are also applicable to this proposal
Solution sketch
Alternatives
Just provide a generic way to tell if two ranges overlap, without actually calculating the overlap, aka #277.
RangeBounds::overlap
is more flexible, since it can operate withoutOrd
orIntoBounds
.Links and related work
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: