diff options
Diffstat (limited to 'vendor/itertools/src/peeking_take_while.rs')
-rw-r--r-- | vendor/itertools/src/peeking_take_while.rs | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/vendor/itertools/src/peeking_take_while.rs b/vendor/itertools/src/peeking_take_while.rs index 3a3722812..b08794a8d 100644 --- a/vendor/itertools/src/peeking_take_while.rs +++ b/vendor/itertools/src/peeking_take_while.rs @@ -1,7 +1,7 @@ -use std::iter::Peekable; use crate::PutBack; #[cfg(feature = "use_alloc")] use crate::PutBackN; +use std::iter::Peekable; /// An iterator that allows peeking at an element before deciding to accept it. /// @@ -11,30 +11,35 @@ use crate::PutBackN; /// This is implemented by peeking adaptors like peekable and put back, /// but also by a few iterators that can be peeked natively, like the slice’s /// by reference iterator (`std::slice::Iter`). -pub trait PeekingNext : Iterator { +pub trait PeekingNext: Iterator { /// Pass a reference to the next iterator element to the closure `accept`; /// if `accept` returns true, return it as the next element, /// else None. fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item> - where Self: Sized, - F: FnOnce(&Self::Item) -> bool; + where + Self: Sized, + F: FnOnce(&Self::Item) -> bool; } impl<'a, I> PeekingNext for &'a mut I - where I: PeekingNext, +where + I: PeekingNext, { fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item> - where F: FnOnce(&Self::Item) -> bool + where + F: FnOnce(&Self::Item) -> bool, { (*self).peeking_next(accept) } } impl<I> PeekingNext for Peekable<I> - where I: Iterator, +where + I: Iterator, { fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item> - where F: FnOnce(&Self::Item) -> bool + where + F: FnOnce(&Self::Item) -> bool, { if let Some(r) = self.peek() { if !accept(r) { @@ -46,10 +51,12 @@ impl<I> PeekingNext for Peekable<I> } impl<I> PeekingNext for PutBack<I> - where I: Iterator, +where + I: Iterator, { fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item> - where F: FnOnce(&Self::Item) -> bool + where + F: FnOnce(&Self::Item) -> bool, { if let Some(r) = self.next() { if !accept(&r) { @@ -65,10 +72,12 @@ impl<I> PeekingNext for PutBack<I> #[cfg(feature = "use_alloc")] impl<I> PeekingNext for PutBackN<I> - where I: Iterator, +where + I: Iterator, { fn peeking_next<F>(&mut self, accept: F) -> Option<Self::Item> - where F: FnOnce(&Self::Item) -> bool + where + F: FnOnce(&Self::Item) -> bool, { if let Some(r) = self.next() { if !accept(&r) { @@ -88,7 +97,8 @@ impl<I> PeekingNext for PutBackN<I> /// for more information. #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] pub struct PeekingTakeWhile<'a, I: 'a, F> - where I: Iterator, +where + I: Iterator, { iter: &'a mut I, f: F, @@ -103,18 +113,16 @@ where /// Create a `PeekingTakeWhile` pub fn peeking_take_while<I, F>(iter: &mut I, f: F) -> PeekingTakeWhile<I, F> - where I: Iterator, +where + I: Iterator, { - PeekingTakeWhile { - iter, - f, - } + PeekingTakeWhile { iter, f } } impl<'a, I, F> Iterator for PeekingTakeWhile<'a, I, F> - where I: PeekingNext, - F: FnMut(&I::Item) -> bool, - +where + I: PeekingNext, + F: FnMut(&I::Item) -> bool, { type Item = I::Item; fn next(&mut self) -> Option<Self::Item> { @@ -127,11 +135,13 @@ impl<'a, I, F> Iterator for PeekingTakeWhile<'a, I, F> } impl<'a, I, F> PeekingNext for PeekingTakeWhile<'a, I, F> - where I: PeekingNext, - F: FnMut(&I::Item) -> bool, +where + I: PeekingNext, + F: FnMut(&I::Item) -> bool, { fn peeking_next<G>(&mut self, g: G) -> Option<Self::Item> - where G: FnOnce(&Self::Item) -> bool, + where + G: FnOnce(&Self::Item) -> bool, { let f = &mut self.f; self.iter.peeking_next(|r| f(r) && g(r)) @@ -174,4 +184,4 @@ peeking_next_by_clone! { ['a, T] alloc::collections::vec_deque::Iter<'a, T> } // cloning a Rev has no extra overhead; peekable and put backs are never DEI. peeking_next_by_clone! { [I: Clone + PeekingNext + DoubleEndedIterator] - ::std::iter::Rev<I> } +::std::iter::Rev<I> } |