Description
This is a tracking issue for the methods Iterator::advance_by
and DoubleEndedIterator::advance_back_by
.
The feature gate for the issue is #![feature(iter_advance_by)]
.
Previously the recommendation was to implement nth
and nth_back
on your iterators to efficiently advance them by multiple elements at once (useful for .skip(n)
and .step_by(n)
). After this feature is stabilized the recommendation will/should be to implement advance_by
and advance_back_by
instead, because they compose better and are often simpler to implement.
Iterators in libcore that wrap another iterator (possibly from elsewhere than libcore) will need to keep their nth
and nth_back
implementations for the foreseeable future and perhaps indefinitely, because the inner iterator may have an efficient nth
implementation without implementing advance_by
as well.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implementation (Add Iterator::advance_by and DoubleEndedIterator::advance_back_by #76909)
- (?) Change advance(_back)_by to return the remainder instead of the number of processed elements #92284
- Stabilization PR (see instructions on rustc-dev-guide)
Implementation history
- Implementation (Add Iterator::advance_by and DoubleEndedIterator::advance_back_by #76909)
- Add tracking issue (Add tracking issue of iter_advance_by feature #77405)
- Implement for
Chain
(Implement advance_by, advance_back_by for iter::Chain #77594) - implement for
slice::{Iter, IterMut}
(Implement advance_by, advance_back_by for slice::{Iter, IterMut} #87387, #[inline] slice::Iter::advance_by #87736) - implement for
vec::IntoIter, ops::Range, iter::{Cycle, Skip, Take, Copied, Flatten}
(implement advance_(back_)_by on more iterators #87091) - Change advance(_back)_by to return the remainder instead of the number of processed elements (Change advance(_back)_by to return the remainder instead of the number of processed elements #92284)