#iterator-adapter #iterator #peek #multipeek

peeking-iter

An iterator adapter that allows infinitely-deep peeking

4 releases

0.2.0 Jul 11, 2024
0.1.2 May 27, 2024
0.1.1 May 27, 2024
0.1.0 May 27, 2024

#783 in Rust patterns

Download history 1/week @ 2024-07-16 22/week @ 2024-07-30 8/week @ 2024-09-10 2/week @ 2024-09-17 6/week @ 2024-09-24 5/week @ 2024-10-01

272 downloads per month

MIT license

13KB
161 lines

peeking-iter

A fast and simple iterator adapter that allows peeking with any depth:

use peeking_iter::PeekingIter

fn main() {
    let it = PeekingIter::new(0..=2);

    assert_eq!(it.next(), Some(0));
    assert_eq!(it.peek(), Some(1));
    assert_eq!(it.peek(), Some(2));
    assert_eq!(it.next(), Some(1));
    assert_eq!(it.peek(), Some(2));
    assert_eq!(it.peek(), None);
}

Why?

  • ~1.5x faster than itertools' MultiPeek
  • Has useful methods initially designed with lexing and parsing in mind (see Parser)

No runtime deps