Trait peeking_take_while::PeekableExt[][src]

pub trait PeekableExt<I>: Iterator where
    I: Iterator
{ fn peeking_take_while<P>(
        &mut self,
        predicate: P
    ) -> PeekingTakeWhile<'_, I, P>
Notable traits for PeekingTakeWhile<'_, I, P>
impl<I, P> Iterator for PeekingTakeWhile<'_, I, P> where
    I: Iterator,
    P: FnMut(&I::Item) -> bool, 
type Item = I::Item;

    where
        P: FnMut(&Self::Item) -> bool
; }
Expand description

The Iterator extension trait that provides the peeking_take_while method.

See the module documentation for details.

Required methods

The peeking_take_while method is very similar to take_while, but behaves differently when used with a borrowed iterator (perhaps returned by Iterator::by_ref).

peeking_take_while peeks at the next item in the iterator and runs the predicate on that peeked item. This avoids consuming the first item yielded by the underlying iterator for which the predicate returns false. On the other hand, take_while will consume that first item for which the predicate returns false, and it will be lost.

In contrast to take_while, iterating the iterator might call the predicate again after it first returned false (the returned iterator isn’t fused). If that is not intended, calling fuse on the returned iterator prevents that.

Implementations on Foreign Types

Implementors