fn find_with_previous<I, F, G>(iterator: &mut I, previous: F, current: G) -> Option<I::Item>
where
    I: Iterator,
    F: Fn(Option<&I::Item>) -> bool,
    G: Fn(&I::Item) -> bool,
{
    match iterator.next() {
        None => None,
        Some(current_item) => {
            if previous(None) && current(&current_item) {
                Some(current_item)
            } else {
                let mut previous_item = current_item;

                // while let Some(current_item) = iterator.next() {
                for current_item in iterator {
                    if previous(Some(&previous_item)) && current(&current_item) {
                        return Some(current_item);
                    }

                    previous_item = current_item;
                }

                None
            }
        }
    }
}
/// Provides much of the same functionality as `Iterator::find` but also
/// provides the previous value if it exists. Use `previous` to test the
/// previous value, and `current` to test the current value (including the the
/// first value). `previous` takes an optional to allow you to specify whether
/// a `true` return from `current` on the first element will stop any further
/// iteration or not.
Provides much of the same functionality as `Iterator::find` but also
provides the previous value if it exists. Use `previous` to test the
previous value, and `current` to test the current value (including the the
first value).
Provides much of the same functionality as ` Iterator :: find ` but also provides the previous value if it exists . Use ` previous ` to test the previous value and ` current ` to test the current value ( including the the first value ) .
fn find_with_previous<I, F, G>(iterator: &mut I, previous: F, current: G) -> Option<I::Item>
where
    I: Iterator,
    F: Fn(Option<&I::Item>) -> bool,
    G: Fn(&I::Item) -> bool,
{
    match iterator.next() {
        None => None,
        Some(current_item) => {
            if previous(None) && current(&current_item) {
                Some(current_item)
            } else {
                let mut previous_item = current_item;
                // while let Some(current_item) = iterator.next() {
                for current_item in iterator {
                    if previous(Some(&previous_item)) && current(&current_item) {
                        return Some(current_item);
                    }
                    previous_item = current_item;
                }
                None
            }
        }
    }
}
fn find_with_previous < I , F , G > ( iterator : & mut I , previous : F , current : G ) -> Option < I :: Item > where I : Iterator , F : Fn ( Option < & I :: Item > ) -> bool , G : Fn ( & I :: Item ) -> bool , { match iterator . next ( ) { None => None , Some ( current_item ) => { if previous ( None ) && current ( & current_item ) { Some ( current_item ) } else { let mut previous_item = current_item ; // while let Some(current_item) = iterator.next() { for current_item in iterator { if previous ( Some ( & previous_item ) ) && current ( & current_item ) { return Some ( current_item ) ; } previous_item = current_item ; } None } } } }
Provides much of the same functionality as `Iterator::find` but also
provides the previous value if it exists.
Provides much of the same functionality as ` Iterator :: find ` but also provides the previous value if it exists .
iterator
&mut I
previous
F
current
G