[][src]Struct libslide::utils::iter::PeekingTakeWhile

struct PeekingTakeWhile<'a, T, P> where
    T: Clone + 'a,
    P: Fn(&T) -> bool
{ peeker: &'a mut PeekIter<T>, predicate: P, }

A TakeWhile-like struct that tests a predicate by peeking rather than consuming an iterator.

rustlib's TakeWhile consumes items in an iterator until its predicate is no longer satisfied. This means that the first item that fails the predicate will also be consumed. For example,

let nums = vec![1, 2, 3, 4, 5];
let mut iter = nums.iter();
let less_than_4: Vec<usize> = iter.by_ref().take_while(|n| **n < 4).cloned().collect();
assert_eq!(less_than_4, &[1, 2, 3]);
assert_eq!(iter.next(), Some(&5)); // 4 was consumed!

PeekingTakeWhile implements a TakeWhile-like functionality without consuming items that fail its predicate.

TODO: Ideally a PeekingTakeWhile would take a Peekable trait object rather than a PeekIter, but rustlib doesn't provide a Peekable trait yet. See the Pre-RFC.

Fields

peeker: &'a mut PeekIter<T>

A mutable reference to the underlying iterator is taken because we actually do want to consume items that match the predicate.

predicate: P

Trait Implementations

impl<'a, T, P> Iterator for PeekingTakeWhile<'a, T, P> where
    T: Clone + 'a,
    P: Fn(&T) -> bool
[src]

type Item = T

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, T, P> RefUnwindSafe for PeekingTakeWhile<'a, T, P> where
    P: RefUnwindSafe,
    T: RefUnwindSafe

impl<'a, T, P> Send for PeekingTakeWhile<'a, T, P> where
    P: Send,
    T: Send

impl<'a, T, P> Sync for PeekingTakeWhile<'a, T, P> where
    P: Sync,
    T: Sync

impl<'a, T, P> Unpin for PeekingTakeWhile<'a, T, P> where
    P: Unpin

impl<'a, T, P> !UnwindSafe for PeekingTakeWhile<'a, T, P>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.