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 upAmend 1192 (RangeInclusive) to use an enum. #1320
Conversation
nrc
added
the
T-libs
label
Oct 15, 2015
alexcrichton
assigned
huonw
Oct 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Hm, I wonder if there's any use for storing the end point, i.e. |
This comment has been minimized.
This comment has been minimized.
|
To expand a little/respond to your rational:
|
This comment has been minimized.
This comment has been minimized.
|
I agree that keeping the end is useful but I don't really get the ownership argument for keeping both. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Nov 3, 2015
|
I think we should back out of RangeInclusive. We need fully general ranges instead which are open/closed/unbounded of both ends. |
This comment has been minimized.
This comment has been minimized.
|
@Stebalien it can be expensive to create/copy/destroy values in Rust (this is in contrast to managed languages, where copying is often just copying a single pointer, or at most manipulating some reference counts), so minimising how often this happens implicitly/without programmer control is good. E.g. if you have a @bluss I agree that having fully general ranges would be nice, but there has been a lot of discussion/thinking about it and AFAIK there has been no nice (and backwards compatible) syntax raised. |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Nov 3, 2015
|
Syntax is a second-order issue for me, which types we want to introduce into the core of rust is much more important. |
This comment has been minimized.
This comment has been minimized.
|
@huonw
I (obviously) agree. However, it may be a bit late for that given that we're stuck with |
This comment has been minimized.
This comment has been minimized.
|
I think |
This comment has been minimized.
This comment has been minimized.
|
Scratch that, I thought Step was used for iterating in general. Not storing start actually saves an allocation because you don't have to allocate a new one when transitioning from |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Nov 3, 2015
|
This comment has been minimized.
This comment has been minimized.
|
@huonw, I've updated the proposal to avoid throwing away the endpoint. I do only need to keep one because, on the last iteration, I can just return the start as-is without advancing it leaving me with the end only. |
This comment has been minimized.
This comment has been minimized.
Oh, that's a good point. |
Stebalien
referenced this pull request
Jan 13, 2016
Merged
implement RFC 1192 inclusive ranges #30884
huonw
added
T-lang
I-nominated
labels
Jan 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Hear ye, hear ye! This RFC is now entering final comment period. |
nikomatsakis
added
final-comment-period
and removed
I-nominated
labels
Jan 15, 2016
This comment has been minimized.
This comment has been minimized.
|
I am
|
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jan 15, 2016
|
Where did the discussion of more complete range syntax go? Mentioned in #1254 |
This comment has been minimized.
This comment has been minimized.
|
That topic seems more relevant for stabilisation of the actual (Maybe you're thinking of https://internals.rust-lang.org/t/vs-for-inclusive-ranges/1539 ?) |
This comment has been minimized.
This comment has been minimized.
bluss
commented
Jan 15, 2016
|
I'm not thinking of that, that's an old discussion. #1254 was much more recent, indicating aturon and lang team wanted to look at this. |
This comment has been minimized.
This comment has been minimized.
|
@bluss Yes, I am on the same page: I want to back out However, as @huonw said, this RFC is just an amendment to the previous one, so it's somewhat orthogonal to the larger question. |
This comment has been minimized.
This comment has been minimized.
|
Libs team consensus: this is a clear improvement over the original RFC. |
liigo
reviewed
Jan 21, 2016
| @@ -37,12 +41,11 @@ pub struct RangeToInclusive<T> { | |||
| } | |||
| ``` | |||
|
|
|||
| Writing `a...b` in an expression desugars to `std::ops::RangeInclusive | |||
| { start: a, end: b, finished: false }`. Writing `...b` in an | |||
| Writing `a...b` in an expression desugars to `std::ops::RangeInclusive::NonEmpty { start: a, end: b }`. Writing `...b` in an | |||
| expression desugars to `std::ops::RangeToInclusive { end: b }`. | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The lang team has decided to accept this RFC. |
nikomatsakis
referenced this pull request
Jan 22, 2016
Closed
Tracking issue for `..=` inclusive ranges (RFC #1192) -- originally `...` #28237
This comment has been minimized.
This comment has been minimized.
|
I kept the same tracking issue, but added a "to do" item to implement the changes suggested here. |
nikomatsakis
merged commit 2025389
into
rust-lang:master
Jan 22, 2016
This comment has been minimized.
This comment has been minimized.
|
Implemented in (in progress) rust-lang/rust#30884. |
This comment has been minimized.
This comment has been minimized.
|
I wonder whether, from a performance perspective, how does the I can't tell if this was suggested at some point, but even if it wasn't, I doubt the implementation will change. |
Stebalien commentedOct 13, 2015
This PR proposes that
RangeInclusivebe an enum withEmpty/NonEmptyvariants instead of a struct with afinishedfield:Rational:
finishedis very iterator specific. Regardless of what happens, I think this field should be calledempty.start/enddon't make sense if the range is empty. Using an enum prevents users from using thestart/endof spent ranges. Basically, this makes it impossible for users to do something likefoo(my_range.take(10)); bar(my_range)and forget to checkfinishedinbar.'a'...'z'should be the same size as'a'..'z'.