-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
What do we guarantee for RangeIter::remainder? #154443
Copy link
Copy link
Open
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-new_range`#![feature(new_range)]``#![feature(new_range)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-new_range`#![feature(new_range)]``#![feature(new_range)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
What should
RangeIter::remainderdo when it came from a non-canonicalRange?For example,
range::Range { start: 10, end: 1 }.into_iter().remainder()-- is it required to be10..1?Perhaps it should return
Option, just likeRangeInclusiveIter::remainder. The question then would be whether it should have the same rule, empty gives none, or a more nuanced rule, perhaps only non-canonical ranges give none.If you iterate from
2..4, stopping at4..4(for forward iteration) or2..2(for backward iteration) is easy enough to guarantee. But it would be kinda nice to just not have to store4..2ever, especially if we could use that to makeOption<RangeIter>niche-optimized.(Said the other way around, if
(a..b).into_iter().remainder()has to always bea..b, then we're prevented from ever optimizing the storage to have niches.)Proposal:
Like
RangeInclusiveIter::remainder, we say thatRangeIter::remainderreturnsNoneif the iterator is exhausted.That gives us two immediately-possible opportunities:
Range::into_iter, since we'll never have to return anything from remainder, and thus can optimize all the methods knowing thatstart > endis never something to worry about.&mut.Nominated because
RangeInclusiveIter::remainderhits stable in under a month, so while I don't think this going to impact that, if we did want to tweak it it'd have to be soon.