- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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.
Description
Feature gate: #![feature(new_range_api)]
This is a tracking issue for the library additions that are part of RFC 3550: New range types
Tracking issue for the language change: #123741
This feature introduces new types implementing Copy and IntoIterator that are meant to replace the legacy range types, which are !Copy and implement Iterator directly.
Public API
// core::range
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct Range<Idx> {
    pub start: Idx,
    pub end: Idx,
}
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct RangeInclusive<Idx> {
    pub start: Idx,
    pub end: Idx,
}
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct RangeFrom<Idx> {
    pub start: Idx,
}
pub struct IterRange<Idx> { <private fields> }
pub struct IterRangeInclusive { <private fields> }
pub struct IterRangeFrom { <private fields> }
impl<Idx: Step> Iterator for IterRange<Idx> { ... }
impl<Idx: Step> Iterator for IterRangeInclusive<Idx> { ... }
impl<Idx: Step> Iterator for IterRangeFrom<Idx> { ... }
impl<Idx: Step> IntoIterator for Range<Idx> {
    type IntoIter = IterRange<Idx>;
    ...
}
impl<Idx: Step> IntoIterator for RangeInclusive<Idx> {
    type IntoIter = IterRangeInclusive<Idx>;
    ...
}
impl<Idx: Step> IntoIterator for RangeFrom<Idx> {
    type IntoIter = IterRangeFrom<Idx>;
    ...
}See the RFC for more details.
Steps / History
-  Implementation: Add new_range_apifor RFC 3550 #125751
-  Inclusive ranges: rename endfield tolast
- Optimize implementation
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
-  Figure out a way to have IterRangeFromoverflow panic only after yielding the maximum value, without impacting release mode
-  How can we / should we optimize IterRangeInclusivenow that it is not bound by the API constraints of legacyRangeInclusive?
-  The set of inherent methods copied from Iteratorpresent on the new range types (Decide which methods to add to newRangetypes #125589)
-  The exact module paths and type names
- Should the new types live at std::ops::range::instead?
- IterRange,- IterRangeInclusiveor just- Iter,- IterInclusive? Or- RangeIter,- RangeInclusiveIter, ...?
 
- Should the new types live at 
-  Should other range-related items (like RangeBounds) also be moved under therangemodule?
-  Should RangeFromeven implementIntoIterator, or should it require an explicit.iter()call? Using it as an iterator can be a footgun, usually people wantstart..=MAXinstead. Also, it is inconsistent withRangeTo, which doesn't implementIntoIteratoreither. But, it's extremely useful forit.zip(1..)
-  Should there be a way to get an iterator that modifies the range in place, rather than taking the range by value? That would allow things like range.by_ref().next().
-  Should there be an infallible conversion from legacy to new RangeInclusive?
impl<Idx> From<legacy::RangeInclusive<Idx>> for RangeInclusive<Idx> {
    // How do we handle the `exhausted` case?
}Footnotes
fwcd, dmyTRUEk, dpytaylo, musjj, manforowicz and 7 morefwcd, mominul, PetrGlad, purplesyringa, musjj and 2 morefmease
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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.