[][src]Crate peekmore

Synopsis:

This crate introduces a multi-peekable iterator. The iterator is similar to 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.

Usage example:

use peekmore::{CreatePeekMoreIterator, PeekView};

let iterable = [1, 2, 3, 4];
let mut iter = iterable.iter().peekmore();

// Peek at the first element.
let v1 = iter.peek();
assert_eq!(v1, Some(&&1));

// Consume the first element.
let v1c = iter.next();
assert_eq!(v1c, Some(&1));

// Peek at the second element (the element in our peek view also moved to the second element,
// since the first element was consumed.)
let v2 = iter.peek();
assert_eq!(v2, Some(&&2));

// Advance the peek view. The peek view will now be at the third element.
let _ = iter.advance_view();

// Check that it is indeed at the third element.
let v3 = iter.peek();
assert_eq!(v3, Some(&&3));

// Reset our peek view to the second element (since the first element has been consumed).
// It is the first non-consumed element.
iter.reset_view();

// Check that we are indeed at the second element again.
let v3 = iter.peek();
assert_eq!(v3, Some(&&2));

// Shift the peek view to the right twice by chaining the advance_view method.
let _ = iter.advance_view().advance_view();

// Verify that the peek view is indeed at the fourth element.
let v4 = iter.peek();
assert_eq!(v4, Some(&&4));

Illustrated example:

An illustrated example can be found at the PeekView::peek documentation.

Structs

PeekMoreIterator

This iterator makes it possible to peek multiple times without consuming a value. In reality the underlying iterator will be consumed, but the values will be stored in a local vector. This vector allows us to shift to visible element (the 'view').

Traits

CreatePeekMoreIterator

Trait which allows one to create an iterator which allows us to peek multiple times forward.

PeekView

Adds functions which enable non-consuming viewing of non-consumed elements of an iterator.