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.


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;;

// Now we're at "swan", which has no elements after it
assert_eq!(iter.peek(), Some(("swan", None)));



Extends an existing Duck or Goose to peek one more element.


Extends a plain Iterator with the ability to peek a single element.



An internal trait that represents either a Duck or a Goose.


An extension trait that adds a .peeking() method to iterators.