-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Description
Feature gate: #![feature(inner_adaptor)]
This is a tracking issue for adding two methods to each iterator adapter containing "only one" adaptor. This two methods allow accessing the inner iterator of the adapter either through non-mutable reference or by consuming the adaptor. A mutable accessor is purposefully not included to prevent logic error and avoid "confusing" the adaptor.
The use case I had was that I wanted to wrap a xmlparser::Tokenizer in a Peekable and a Filter but still have access to some of its method (that are only available in my fork of it and currently being merged). This method are not specifically iterator related but allow access to the inner UTF-8 stream of the tokenizer for example.
In more details, the current choice on whether to implement this method is:
Implemented
ClonedCopiedEnumerateFilterFilterMapInspectIntersperceMapWhileMapPeekable: Can be confusing because the inner iterator is "one step further" if it has been peeked. Would documentation be enough?RevScanSkip_WhileSkipStepByTakeWhileTakeZip: has two iterators so one by-ref accessor for each and one conssuming accessor returning a tuple.
Not implemented
chain: Has two iteratorscycle: Unclear which iterator this should refer toFuse: Would not make sense when fused, except if returningOptionbut then the API becomes a bit confusing compared to others
Unclear
array_chunks: Could lead to confusion depending on how the underlying iterator is consummedby_ref_sized: Unclear if meant to be used publicly at some pointFlatten: Unclear if it would make sense to return the underlying "top-level" iterator
Public API
The basic API is akin to:
//
use std::iter::map
pub struct Map<I,F>;
impl<I, F> Map<I, F> {
pub fn inner(&self) -> &I;
pub fn into_inner(self) -> I {}
}but has some adaptations depending on the case.
Steps / History
Most of the work that remains centers around whether to implement it for cases that can be confusing, and under what documentation constraints.
- Implementation: Draft: Add inner and into_inner methods to iterator adapters #103294
- Decide what to do with
Peekable - Decide what to do with
Flatten - Decide what to do with
ByRefSized - Decide what to do with
ArrayChunks
- Decide what to do with
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Decide what to do with
Peekable - Decide what to do with
Flatten - Decide what to do with
ByRefSized - Decide what to do with
ArrayChunks