Crate duck [−] [src]
This crate exposes a .peeking()
method, for looking at the next element in
an iterator without consuming it.
Unlike the peekable
method in the standard library, peeking
can be
stacked. This means that chaining multiple calls of peeking
will
increase the number of elements returned by peek
.
Note that this library will .clone()
the elements that are peeked. While
this is not strictly necessary, it does make the implementation much easier
to understand, especially given the lack of generic associated types in
current Rust.
Example
let anatids = vec!["duck", "goose", "swan"]; // Since .peeking() is called twice, this iterator will peek two elements ahead let mut iter = anatids.into_iter().peeking().peeking(); assert_eq!(iter.peek(), Some(("duck", Some("goose")))); // Step the iterator twice iter.next(); iter.next(); // Now we're at "swan", which has no elements after it assert_eq!(iter.peek(), Some(("swan", None)));
Structs
Duck |
Extends an existing |
Goose |
Extends a plain |
Traits
Anatid |
An internal trait that represents either a |
PeekingExt |
An extension trait that adds a |