#iterator #iterator-adapter #peek #no-alloc

no-std fastpeek

A different way to peek iterators

7 releases

0.2.6 Sep 30, 2024
0.2.5 Sep 28, 2024
0.1.1 Sep 26, 2024

#1140 in Rust patterns

Download history 618/week @ 2024-09-26 32/week @ 2024-10-03 11/week @ 2024-10-10 3/week @ 2024-10-17

664 downloads per month

MIT/Apache

18KB
437 lines

fastpeek rust-version-badge

When you need to do fast iteration, std::iter::Peekable adds some overhead because it has to check if it has a buffered value on each call to next(). This crate provides tree simple traits that can be implemented for iterators where the aim is to peek without calling next(). In addition to a normal single value forward peek, the crate has traits for peeking a DoubleEndedIterator, and for peeking multiple values through an iterator.

The crate does not necessarily aim to make peeking faster, but to remove the overhead of std::iter::Peekable when doing normal iteration.

The crate contains implementations for all Iterators that implement AsRef<[T]> plus std::array::IntoIter. In addition, Iterator adapters using various strategies to provide Peek are provided.

No runtime deps