-
Notifications
You must be signed in to change notification settings - Fork 14k
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(peekable_iterator)]
This is a tracking issue for the PeekableIterator trait, which extends Iterator with peek_with and related methods that inspect the next element without consuming it.
Public API
// core::iter
pub trait PeekableIterator: Iterator {
// required method
fn peek_with<T>(&mut self, func: impl for<'a> FnOnce(Option<&'a Self::Item>) -> T) -> T;
// provided methods
fn peek_map<T>(&mut self, func: impl for<'a> FnOnce(&'a Self::Item) -> T) -> Option<T>;
fn next_if(&mut self, func: impl FnOnce(&Self::Item) -> bool) -> Option<Self::Item>;
fn next_if_eq<T>(&mut self, expected: &T) -> Option<Self::Item>
where
Self::Item: PartialEq<T>,
T: ?Sized;
}Steps / History
- ACP:
Peektrait for peekable iterators libs-team#176 - Implementation:
- Take 1: Add
PeekableIteratortrait #132976 - Take 2: Add
PeekableIteratortrait #144935
- Take 1: Add
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- Should
peektake&mut selfor&self?&selfmakes sense for iterators such ascore::slice::iterbut precludes implementing the trait onPeekable. What about the return type ofResolved by having the method take a callback.peek? We could always make it returnSelf::Itemlike itertools’sPeekingNext, but that would prevent this trait from being implemented for consuming iterators such asvec::IntoIter, as well asPeekableitself.If we use an associated type, then what should be the bound for it:Borrow,AsRef, or something else?
Footnotes
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.