Skip to content

Add a PeekableIter trait in standard library. #18401

Closed
@PhilLavoie

Description

@PhilLavoie

We already have a Peekable concrete type that makes it easy for already defined iterators to provide a peek function. I would like to suggest adding a standard trait that defines peekable iterator's behavior: peek and is_empty and next so that users can provide their own optimized peekable iterators, possibly avoiding the intermediate copy made by Peekable for example, but also because this:

fn parse< C, P: PeekableIter< C > >(iter: P) {...}

Looks better than

fn pase< C, I: Iterator< C > >(iter: Peekable< C, I >) {
  ...
 //Keep in mind that peekable returns a reference and not the actual C type.
 ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions