Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for Range*::contains #32311
Comments
alexcrichton
added
B-RFC-approved
T-libs
labels
Mar 17, 2016
This comment has been minimized.
This comment has been minimized.
|
I am unsure what part of the rfc was accepted. Is the |
This comment has been minimized.
This comment has been minimized.
|
The accepted portion of an RFC is the detailed design, which in this case only deals with ranges, not iterators. |
This comment has been minimized.
This comment has been minimized.
|
Well, okay. Fine. |
This comment has been minimized.
This comment has been minimized.
|
It is in fact also compatible with future extension to iterators. |
This comment has been minimized.
This comment has been minimized.
|
Should this be implemented for (unstable) |
This comment has been minimized.
This comment has been minimized.
|
For consistency, yeah, seems prudent. |
nodakai
added a commit
to nodakai/rust
that referenced
this issue
Mar 21, 2016
nodakai
added a commit
to nodakai/rust
that referenced
this issue
Mar 22, 2016
nodakai
added a commit
to nodakai/rust
that referenced
this issue
Mar 24, 2016
bors
added a commit
that referenced
this issue
Mar 25, 2016
bors
added a commit
that referenced
this issue
Mar 25, 2016
This comment has been minimized.
This comment has been minimized.
|
Hm, I just used this and expected it to take Looking back the RFC, it does not seem to consider this case - was there any discussion for this possibility? |
alexcrichton
added
B-unstable
and removed
B-RFC-approved
labels
Jun 21, 2016
This comment has been minimized.
This comment has been minimized.
|
Hi, This RFC doesn't address
|
This comment has been minimized.
This comment has been minimized.
|
Hm, my elation turned into sadness today when I added a
I can only imagine that method resolution works this way for the sake of backwards compatibility, but... yikes! Since this change is "compatible with future extension to iterators," I take it that there is a way to implement an |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge Seem like nifty methods to stabilize! |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 1, 2016
•
|
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern previous-questions I see three previous comments asking about the API here. I don't know anything about this API but it's not obvious it's ready for stabilization. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp cancel Ok, sounds like these aren't ready yet. |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 4, 2016
|
@alexcrichton proposal cancelled. |
This comment has been minimized.
This comment has been minimized.
|
A thought on impl<Idx, T> Range<Idx> where T:PartialOrd<Idx>, Idx:PartialOrd<T> {
pub fn contains(&self, item: T) -> bool {
(self.start <= item) && (item < self.end)
}
}So it's totally fine if Idx=T (the two constraints collapse to the current one, and a caller could just require Idx:PartialOrd), but would allow checking a (Edit: adding backticks so the angle brackets show up) |
This comment has been minimized.
This comment has been minimized.
|
Any status update on this? |
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
Jun 29, 2017
|
Ping? |
This comment has been minimized.
This comment has been minimized.
|
The FCP for merge was canceled due to unresolved questions, and it looks like those unresolved questions have not been resolved. |
This comment has been minimized.
This comment has been minimized.
|
Just regarding the questions about the current implementation:
I'd suggest the most reasonable implementation would be something like: impl<Idx> Range<Idx> {
pub fn contains<T>(&self, item: &T) -> bool
where Idx: PartialOrd, Idx: PartialOrd<T> {
if self.start <= self.end {
self.start <= *item && self.end > *item
} else {
self.start <= *item || self.end > *item
}
}
}1 is going to break existing uses; 2 should be implementable without breaking anything; 3 changes behaviour, so would be a breaking change. As the current implementation falls short of the expected behaviour, it seems to me like this is a change worth making. |
This comment has been minimized.
This comment has been minimized.
|
Though I still feel it's better to handle the |
This comment has been minimized.
This comment has been minimized.
Riamse
commented
Jan 29, 2018
|
It would be nice if you could make it a trait instead of a directly implemented method so that you can see if a range contains a number without having to worry about whether it's a RangeFull, Range, RangeFrom, etc. It would enable you to do something like fn pi_in_range<T: ContainRange>(range: T) -> bool {
range.contains(3.141592653589793238462643383)
}
// ...
assert!(pi_in_range(0.0 .. 10.0);
assert!(pi_in_range(..10.0);
assert!(!pi_in_range(10.0..);
assert!(pi_in_range(..); |
kennytm
referenced this issue
Mar 9, 2018
Open
Mini-RFC: Finalize syntax for slice patterns with subslices #2359
This comment has been minimized.
This comment has been minimized.
|
I'd like to second @lukaramu's and others' comments above, I really think this should be moved to be a trait method on RangeArgument instead of implemented on each range type exclusively. There could probably even be a default impl that just depends on start and end and works for everything. Edit: See my PR below which does this. |
smmalis37
referenced this issue
Mar 18, 2018
Merged
Move Range*::contains to a single default impl on RangeBounds #49130
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
Apr 8, 2018
|
@lukaramu why you don't believe |
bors
added a commit
that referenced
this issue
Apr 16, 2018
This comment has been minimized.
This comment has been minimized.
|
The two Implementation Work items have now been done. The question about Wrapping types still remains. |
This comment has been minimized.
This comment has been minimized.
|
My personal opinion on the question of Wrapping types: If you look at the new contains implementation it's hard to argue that it could be incorrect in some way. It seems completely reasonable to say that a range contains something iff that something is greater than the start and less than the end. If the Wrapping types don't work within these guidelines that feels to me more like a bug in their PartialOrd implementation. This could potentially be solved with specialization though. |
This comment has been minimized.
This comment has been minimized.
|
I'd like to suggest this for stabilization. I agree with the previous comment that the current implementation is fine for (If we had never implemented Ord and PartialOrd for Wrapping, then we could argue differently, but it is too late for that.) |
This comment has been minimized.
This comment has been minimized.
|
cc @SimonSapin |
This comment has been minimized.
This comment has been minimized.
|
The comments above on @rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jan 4, 2019
•
|
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Jan 4, 2019
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jan 28, 2019
|
|
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Jan 28, 2019
rfcbot
added
the
finished-final-comment-period
label
Feb 7, 2019
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Feb 7, 2019
|
The final comment period, with a disposition to merge, as per the review above, is now complete. |
alexcrichton commentedMar 17, 2016
•
edited by Mark-Simulacrum
Tracking issue for rust-lang/rfcs#1434.
Unresolved questions:
Wrappingranges.Implementation work: