Stabilize iter_advance_by - #163328
Stabilize iter_advance_by#163328theemathas wants to merge 1 commit into
iter_advance_by#163328Conversation
This comment has been minimized.
This comment has been minimized.
d9f38e8 to
8149c5f
Compare
|
cc @rust-lang/miri |
|
r? @Darksonn rustbot has assigned @Darksonn. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @ChrisDenton |
|
@rfcbot merge libs |
|
@ChrisDenton has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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! cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns. |
This comment has been minimized.
This comment has been minimized.
8149c5f to
620dc09
Compare
This comment has been minimized.
This comment has been minimized.
Currently we're not even doing that for Personally I want to be about as aggressive about eliding effects as I can get away with and introducing a new method whose semantics nobody relies on is a good opportunity for that. Other iterator adapters can then build on this capability (if not the std adapters due to backcompat, then at least |
620dc09 to
f22d0cb
Compare
|
@the8472 We currently skip over cloning in the implementation for rust/library/core/src/iter/sources/repeat.rs Lines 91 to 96 in ecd8f1d |
It looks like currently advance_by doesn't attempt to forward to nth to allow migrating here. Is there some discussion of why that isn't feasible? The tracking issue says this can't be be done because "advance_by returns the number of items you can't implement in terms of .nth() which was the previous recommended way to skip elements." -- do we think the Err variant of advance_by is useful enough that we should keep it? What is the intended purpose of the skipped length? I think this isn't blocking necessarily, but I think the stabilization report should include more thought on this than ("There doesn't seem to be an ideal solution, but I don't think we should let that block stabilization."). What (else) did we consider? @rfcbot concern nth-advance-by |
The |
|
@rustbot label +S-waiting-on-t-libs -S-waiting-on-review |
|
not something that blocks stabilization, but I noticed a missing impl of |
Closes #77404 (tracking issue)
See also zulip discussion: #t-libs > Status of `Iterator::advance_by`?
Implementation history
Chain(Implement advance_by, advance_back_by for iter::Chain #77594)slice::{Iter, IterMut}(Implement advance_by, advance_back_by for slice::{Iter, IterMut} #87387, #[inline] slice::Iter::advance_by #87736)vec::IntoIter, ops::Range, iter::{Cycle, Skip, Take, Copied, Flatten}(implement advance_(back_)_by on more iterators #87091)API being stabilized
If the advancement causes an attempt to iterate past the end of the iterator, the method returns an
Errwith the number of steps that are remaining by the time the iterator has hit the end.Calling
.advance_by(0)may meaningfully mutate the iterator. As the documentation says:Experience Report
The feature is quite a popular unstable feature, as can be seen from the github search results, which finds 2k files.
The tracking issue also has many emoji reactions (currently at 27 hearts), which indicates a desire for this API.
Potential issues / questions
where Self: Sizedbound to reduce the vtable size? (The only other methods in the vtable arenext,size_hint, andnth.) Tracking Issue for feature(iter_advance_by) #77404 (comment)advance_by.nthoradvance_byfor the best performance? Calling.advance_bymight skip the need to actually generate the element, while callingnthwould work better with iterator implementations that implementnth(since it was stabilized first), but notadvance_by. Tracking Issue for feature(iter_advance_by) #77404 (comment)advance_bybe guaranteed to perform side-effects of producing the skipped-over elements? Tracking Issue for feature(iter_advance_by) #77404 (comment)nextforwards to a method that is conventionally pure, such asClone.Ok(&mut self)in order to enable method chaining? #t-libs > Status of `Iterator::advance_by`? @ 💬dyn Iteratorthat forward to it. I think the ability to chain is of questionable benefit anyway.