#peek #lookahead #iterator #peekable #multipeek

no-std peekmore

Iterator adapter like Peekable, but for peeking forward multiple elements

17 releases (5 stable)

1.3.0 Jun 5, 2023
1.2.0 Mar 16, 2023
1.0.0 Dec 30, 2020
0.5.6 Aug 27, 2020
0.4.0 Sep 20, 2019

#19 in No standard library

Download history 1381/week @ 2023-11-01 1104/week @ 2023-11-08 991/week @ 2023-11-15 1059/week @ 2023-11-22 869/week @ 2023-11-29 995/week @ 2023-12-06 1154/week @ 2023-12-13 501/week @ 2023-12-20 421/week @ 2023-12-27 248/week @ 2024-01-03 292/week @ 2024-01-10 456/week @ 2024-01-17 501/week @ 2024-01-24 583/week @ 2024-01-31 539/week @ 2024-02-07 595/week @ 2024-02-14

2,283 downloads per month
Used in 23 crates (13 directly)

MIT/Apache

69KB
1K SLoC

peekmore

This crate introduces a multi-peekable iterator. The iterator is similar to core::iterator::Peekable. The main difference is that Peekable only allows you to peek at the next element and no further. This crate aims to take that limitation away.

The documentation and more extensive example usage can be found at docs.rs/peekmore.

Usage example:

use peekmore::PeekMore;

fn main() {
    let range10 = 0..11;
    let mut peekable = range10.peekmore();
    
    // Peek at the first element
    let peek_first = peekable.peek();
    assert_eq!(*peek_first.unwrap(), 0);
    
    let peek_first_redux = peekable.peek_nth(0);
    assert_eq!(*peek_first_redux.unwrap(), 0);
    
    // Peek at the 10th (index) element
    let peek_tenth = peekable.peek_nth(10);
    assert_eq!(*peek_tenth.unwrap(), 10);
    
    // Consume the 10th element
    let tenth = peekable.nth(10);
    assert_eq!(tenth.unwrap(), 10);
    
    // Show that there are no more elements
    assert_eq!(peekable.peek(), None);
    assert_eq!(peekable.next(), None);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies