pub struct Peekable<'this, L>where
L: Lender,{ /* private fields */ }Expand description
A lender with a peek() method that returns an optional
reference to the next element.
This struct is created by the peekable()
method on Lender.
Implementations§
Source§impl<'this, L> Peekable<'this, L>where
L: Lender,
impl<'this, L> Peekable<'this, L>where
L: Lender,
Sourcepub fn into_inner(self) -> L
pub fn into_inner(self) -> L
Returns the inner lender.
Sourcepub fn peek(&mut self) -> Option<&Lend<'_, L>>
pub fn peek(&mut self) -> Option<&Lend<'_, L>>
Returns a reference to the next element without advancing the lender.
Like next, if there is a next value, it is borrowed from the
underlying lender and cached. Calling peek() multiple times without advancing
the lender returns the same cached element.
§Examples
let mut lender = [1, 2, 3].iter().into_lender().peekable();
assert_eq!(lender.peek(), Some(&&1));
assert_eq!(lender.peek(), Some(&&1)); // Doesn't advance
assert_eq!(lender.next(), Some(&1));
assert_eq!(lender.peek(), Some(&&2));Sourcepub fn peek_mut(&mut self) -> Option<&mut Lend<'this, L>>
pub fn peek_mut(&mut self) -> Option<&mut Lend<'this, L>>
Returns a mutable reference to the next element without advancing the lender.
Like peek, if there is a next value, it is borrowed from the
underlying lender and cached. The returned mutable reference allows modifying
the peeked value.
§Examples
let mut lender = [1, 2, 3].iter().into_lender().peekable();
if let Some(p) = lender.peek_mut() {
// p is &mut &i32, so we replace the reference
*p = &10;
}
assert_eq!(lender.next(), Some(&10));
assert_eq!(lender.next(), Some(&2));Sourcepub fn next_if<F>(&mut self, f: F) -> Option<Lend<'_, L>>
pub fn next_if<F>(&mut self, f: F) -> Option<Lend<'_, L>>
Consumes and returns the next element if the given predicate is true.
If f(&next_element) returns true, consumes and returns the next element.
Otherwise, returns None and the element remains peeked.
§Examples
let mut lender = [1, 2, 3].iter().into_lender().peekable();
// Consume 1 since it's odd
assert_eq!(lender.next_if(|&x| *x % 2 == 1), Some(&1));
// Don't consume 2 since it's not odd
assert_eq!(lender.next_if(|&x| *x % 2 == 1), None);
// 2 is still there
assert_eq!(lender.next(), Some(&2));Sourcepub fn next_if_eq<'a, T>(&'a mut self, t: &T) -> Option<Lend<'a, L>>
pub fn next_if_eq<'a, T>(&'a mut self, t: &T) -> Option<Lend<'a, L>>
Consumes and returns the next element if it equals the given value.
If the next element equals t, consumes and returns it. Otherwise,
returns None and the element remains peeked.
§Examples
let mut lender = [1, 2, 3].iter().into_lender().peekable();
// Consume 1 since it equals 1
assert_eq!(lender.next_if_eq(&&1), Some(&1));
// Don't consume 2 since it doesn't equal 1
assert_eq!(lender.next_if_eq(&&1), None);
// 2 is still there
assert_eq!(lender.next(), Some(&2));Trait Implementations§
Source§impl<'this, L: DoubleEndedLender> DoubleEndedLender for Peekable<'this, L>
impl<'this, L: DoubleEndedLender> DoubleEndedLender for Peekable<'this, L>
Source§fn next_back(&mut self) -> Option<Lend<'_, Self>>
fn next_back(&mut self) -> Option<Lend<'_, Self>>
Source§fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
Lender::try_fold: it takes elements starting from
the back of the lender. Read moreSource§fn rfold<B, F>(self, init: B, f: F) -> B
fn rfold<B, F>(self, init: B, f: F) -> B
Lender::fold: it takes elements starting from
the back of the lender. Read moreSource§fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
n elements. Read moreSource§impl<L: ExactSizeLender> ExactSizeLender for Peekable<'_, L>
impl<L: ExactSizeLender> ExactSizeLender for Peekable<'_, L>
Source§impl<'this, L> Lender for Peekable<'this, L>where
L: Lender,
impl<'this, L> Lender for Peekable<'this, L>where
L: Lender,
Source§fn __check_covariance<'long: 'short, 'short>(
proof: CovariantProof<<Self as Lending<'long>>::Lend>,
) -> CovariantProof<<Self as Lending<'short>>::Lend>
fn __check_covariance<'long: 'short, 'short>( proof: CovariantProof<<Self as Lending<'long>>::Lend>, ) -> CovariantProof<<Self as Lending<'short>>::Lend>
Source§fn next(&mut self) -> Option<Lend<'_, Self>>
fn next(&mut self) -> Option<Lend<'_, Self>>
Source§fn last<'a>(&'a mut self) -> Option<Lend<'a, Self>>where
Self: Sized,
fn last<'a>(&'a mut self) -> Option<Lend<'a, Self>>where
Self: Sized,
Source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
.len() for the exact length if the lender
implements ExactSizeLender. Read moreSource§fn next_chunk(&mut self, chunk_size: usize) -> Chunk<'_, Self>where
Self: Sized,
fn next_chunk(&mut self, chunk_size: usize) -> Chunk<'_, Self>where
Self: Sized,
chunk_size lends of the lender with temporary lender
Chunk. This is equivalent to cloning the lender and calling
take(chunk_size) on it. Read moreSource§fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize>
n lends. Read moreSource§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
step - 1 lends between each lend of the lender. Read moreSource§fn chain<U>(self, other: U) -> Chain<Self, <U as IntoLender>::Lender>
fn chain<U>(self, other: U) -> Chain<Self, <U as IntoLender>::Lender>
Source§fn zip<U: IntoLender>(self, other: U) -> Zip<Self, <U as IntoLender>::Lender>where
Self: Sized,
fn zip<U: IntoLender>(self, other: U) -> Zip<Self, <U as IntoLender>::Lender>where
Self: Sized,
Source§fn intersperse<'call>(
self,
separator: Lend<'call, Self>,
) -> Intersperse<'call, Self>
fn intersperse<'call>( self, separator: Lend<'call, Self>, ) -> Intersperse<'call, Self>
Source§fn intersperse_with<'call, G>(
self,
separator: G,
) -> IntersperseWith<'call, Self, G>
fn intersperse_with<'call, G>( self, separator: G, ) -> IntersperseWith<'call, Self, G>
Source§fn map<F>(self, f: Covar<F>) -> Map<Self, F>
fn map<F>(self, f: Covar<F>) -> Map<Self, F>
Source§fn map_into_iter<O, F: FnMut(Lend<'_, Self>) -> O>(
self,
f: F,
) -> MapIntoIter<Self, O, F> ⓘwhere
Self: Sized,
fn map_into_iter<O, F: FnMut(Lend<'_, Self>) -> O>(
self,
f: F,
) -> MapIntoIter<Self, O, F> ⓘwhere
Self: Sized,
Source§fn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Source§fn filter_map<F>(self, f: Covar<F>) -> FilterMap<Self, F>
fn filter_map<F>(self, f: Covar<F>) -> FilterMap<Self, F>
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Source§fn peekable<'call>(self) -> Peekable<'call, Self>where
Self: Sized,
fn peekable<'call>(self) -> Peekable<'call, Self>where
Self: Sized,
Source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n lends of this lender. Read moreSource§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n lends of this lender. Read moreSource§fn mutate<F>(self, f: F) -> Mutate<Self, F>
fn mutate<F>(self, f: F) -> Mutate<Self, F>
Source§fn collect<B>(self) -> Bwhere
Self: Sized,
B: FromLender<Self>,
fn collect<B>(self) -> Bwhere
Self: Sized,
B: FromLender<Self>,
Source§fn try_collect<'a, B>(&'a mut self) -> ChangeOutputType<Lend<'a, Self>, B>
fn try_collect<'a, B>(&'a mut self) -> ChangeOutputType<Lend<'a, Self>, B>
Source§fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
Self: Sized,
E: ExtendLender<Self>,
fn collect_into<E>(self, collection: &mut E) -> &mut Ewhere
Self: Sized,
E: ExtendLender<Self>,
Source§fn is_partitioned<P>(self, predicate: P) -> bool
fn is_partitioned<P>(self, predicate: P) -> bool
Source§fn try_for_each<F, R>(&mut self, f: F) -> R
fn try_for_each<F, R>(&mut self, f: F) -> R
Source§fn try_reduce<T, F, R>(self, f: F) -> ChangeOutputType<R, Option<T>>
fn try_reduce<T, F, R>(self, f: F) -> ChangeOutputType<R, Option<T>>
Source§fn find_map<'a, F>(
&'a mut self,
f: F,
) -> Option<<F as FnMutHKAOpt<'a, Lend<'a, Self>>>::B>
fn find_map<'a, F>( &'a mut self, f: F, ) -> Option<<F as FnMutHKAOpt<'a, Lend<'a, Self>>>::B>
Source§fn max_by_key<B: Ord, T, F>(self, f: F) -> Option<T>
fn max_by_key<B: Ord, T, F>(self, f: F) -> Option<T>
Source§fn min_by_key<B: Ord, T, F>(self, f: F) -> Option<T>
fn min_by_key<B: Ord, T, F>(self, f: F) -> Option<T>
Source§fn unzip<ExtA, ExtB>(self) -> (ExtA, ExtB)where
Self: Sized,
for<'all> Lend<'all, Self>: TupleLend<'all>,
ExtA: Default + ExtendLender<FirstShunt<Self>>,
ExtB: Default + ExtendLender<SecondShunt<Self>>,
fn unzip<ExtA, ExtB>(self) -> (ExtA, ExtB)where
Self: Sized,
for<'all> Lend<'all, Self>: TupleLend<'all>,
ExtA: Default + ExtendLender<FirstShunt<Self>>,
ExtB: Default + ExtendLender<SecondShunt<Self>>,
Source§fn product<P>(self) -> Pwhere
Self: Sized,
P: ProductLender<Self>,
fn product<P>(self) -> Pwhere
Self: Sized,
P: ProductLender<Self>,
Source§fn partial_cmp<L>(self, other: L) -> Option<Ordering>
fn partial_cmp<L>(self, other: L) -> Option<Ordering>
Source§fn partial_cmp_by<L, F>(self, other: L, partial_cmp: F) -> Option<Ordering>
fn partial_cmp_by<L, F>(self, other: L, partial_cmp: F) -> Option<Ordering>
Source§fn is_sorted_by<T, F>(self, compare: F) -> bool
fn is_sorted_by<T, F>(self, compare: F) -> bool
Source§fn is_sorted_by_key<F, K>(self, f: F) -> bool
fn is_sorted_by_key<F, K>(self, f: F) -> bool
Source§fn lender_by_ref<'this>(self) -> FromIterRef<Iter<'this, Self>>
fn lender_by_ref<'this>(self) -> FromIterRef<Iter<'this, Self>>
Source§fn chunky(self, chunk_size: usize) -> Chunky<Self>where
Self: Sized + ExactSizeLender,
fn chunky(self, chunk_size: usize) -> Chunky<Self>where
Self: Sized + ExactSizeLender,
Iterator::array_chunks. Read moreSource§fn convert<E>(self) -> Convert<E, Self>where
Self: Sized,
fn convert<E>(self) -> Convert<E, Self>where
Self: Sized,
Lender whose lend type is Result<T, E> into a
FallibleLender with error type E and lend type T. Read moreSource§fn into_fallible(self) -> IntoFallible<Self>where
Self: Sized,
fn into_fallible(self) -> IntoFallible<Self>where
Self: Sized,
Lender into a FallibleLender
by wrapping into Result<Lend<'_, Self>, Infallible> where
Infallible is an error that can never actually happen. Read more