fn advance_iter<P, I>(
    source: P,
    iter: &mut Peekable<I>,
    golden: &OsStr,
) -> Result<Entry, DirCompareError>
where
    P: AsRef<Path>,
    I: Iterator<Item = walkdir::Result<Entry>>,
{
    loop {
        let result = iter.peek().ok_or_else(|| {
            DirCompareError::MissingEntry(source.as_ref().join(golden.to_owned()).into_os_string())
        })?;

        let item = match result {
            Ok(value) => value,
            Err(_) => {
                // Why this is safe:
                // - We successfully peeked the iterator, so this item exists.
                // - It is an error type.
                //
                // This hackery is a kludge to allow the "non-error" case
                // to continue operating on a non-owned reference, but
                // permitting the error case to take ownership of the error.
                let err = iter.next().unwrap().unwrap_err();
                return Err(DirCompareError::WalkDir(err));
            }
        };

        match item.path.as_path().cmp(Path::new(golden)) {
            Ordering::Less => {
                let _ = iter.next();
            }
            Ordering::Equal => {
                return Ok(item.clone());
            }
            Ordering::Greater => {
                return Err(DirCompareError::MissingEntry(
                    source.as_ref().join(golden.to_owned()).into_os_string(),
                ));
            }
        }
    }
}
// Move `iter` forward until it returns an entry matching `golden`.
// Returns the DirEntry which contains `golden`.
Move `iter` forward until it returns an entry matching `golden`.
Returns the DirEntry which contains `golden`.
Move ` iter ` forward until it returns an entry matching ` golden ` . Returns the DirEntry which contains ` golden ` .
fn advance_iter<P, I>(
    source: P,
    iter: &mut Peekable<I>,
    golden: &OsStr,
) -> Result<Entry, DirCompareError>
where
    P: AsRef<Path>,
    I: Iterator<Item = walkdir::Result<Entry>>,
{
    loop {
        let result = iter.peek().ok_or_else(|| {
            DirCompareError::MissingEntry(source.as_ref().join(golden.to_owned()).into_os_string())
        })?;
        let item = match result {
            Ok(value) => value,
            Err(_) => {
                // Why this is safe:
                // - We successfully peeked the iterator, so this item exists.
                // - It is an error type.
                //
                // This hackery is a kludge to allow the "non-error" case
                // to continue operating on a non-owned reference, but
                // permitting the error case to take ownership of the error.
                let err = iter.next().unwrap().unwrap_err();
                return Err(DirCompareError::WalkDir(err));
            }
        };
        match item.path.as_path().cmp(Path::new(golden)) {
            Ordering::Less => {
                let _ = iter.next();
            }
            Ordering::Equal => {
                return Ok(item.clone());
            }
            Ordering::Greater => {
                return Err(DirCompareError::MissingEntry(
                    source.as_ref().join(golden.to_owned()).into_os_string(),
                ));
            }
        }
    }
}
fn advance_iter < P , I > ( source : P , iter : & mut Peekable < I > , golden : & OsStr , ) -> Result < Entry , DirCompareError > where P : AsRef < Path > , I : Iterator < Item = walkdir :: Result < Entry > > , { loop { let result = iter . peek ( ) . ok_or_else ( | | { DirCompareError :: MissingEntry ( source . as_ref ( ) . join ( golden . to_owned ( ) ) . into_os_string ( ) ) } ) ? ; let item = match result { Ok ( value ) => value , Err ( _ ) => { // Why this is safe: // - We successfully peeked the iterator, so this item exists. // - It is an error type. // // This hackery is a kludge to allow the "non-error" case // to continue operating on a non-owned reference, but // permitting the error case to take ownership of the error. let err = iter . next ( ) . unwrap ( ) . unwrap_err ( ) ; return Err ( DirCompareError :: WalkDir ( err ) ) ; } } ; match item . path . as_path ( ) . cmp ( Path :: new ( golden ) ) { Ordering :: Less => { let _ = iter . next ( ) ; } Ordering :: Equal => { return Ok ( item . clone ( ) ) ; } Ordering :: Greater => { return Err ( DirCompareError :: MissingEntry ( source . as_ref ( ) . join ( golden . to_owned ( ) ) . into_os_string ( ) , ) ) ; } } } }
Move `iter` forward until it returns an entry matching `golden`.
Move ` iter ` forward until it returns an entry matching ` golden ` .
source
P
iter
&mut Peekable<I>
golden
&OsStr
source
P
iter
&mut Peekable<I>
golden
&OsStr