fn iter_dirs(dir: &Path) -> io::Result<Vec<PathBuf>> {
    let mut stack = vec![fs::read_dir(dir)?];
    let mut files = vec![];
    // Look out for our future dive into Vectors and their various uses!
    while let Some(dir) = stack.last_mut() {
        // Transpose says: Take that Option<Result> and turn it into a Result<Option>!
        match dir.next().transpose()? {
            None => {
                stack.pop();
            }
            // A Some! But only if it's the kind of Some we want
            Some(dir) if dir.file_type().map_or(false, |t| t.is_dir()) => {
                stack.push(fs::read_dir(dir.path())?);
            }
            Some(file) => files.push(file.path()),
        }
    }
    Ok(files)
}
/// Recursively visits a path, returning a flattened list of ALL items
/// at or below the path
/// Iterative version
Recursively visits a path, returning a flattened list of ALL items
at or below the path
Iterative version
Recursively visits a path returning a flattened list of ALL items at or below the path Iterative version
fn iter_dirs(dir: &Path) -> io::Result<Vec<PathBuf>> {
    let mut stack = vec![fs::read_dir(dir)?];
    let mut files = vec![];
    // Look out for our future dive into Vectors and their various uses!
    while let Some(dir) = stack.last_mut() {
        // Transpose says: Take that Option<Result> and turn it into a Result<Option>!
        match dir.next().transpose()? {
            None => {
                stack.pop();
            }
            // A Some! But only if it's the kind of Some we want
            Some(dir) if dir.file_type().map_or(false, |t| t.is_dir()) => {
                stack.push(fs::read_dir(dir.path())?);
            }
            Some(file) => files.push(file.path()),
        }
    }
    Ok(files)
}
fn iter_dirs ( dir : & Path ) -> io :: Result < Vec < PathBuf > > { let mut stack = vec ! [ fs read_dir ( dir ) ] ; let mut files = vec ! [ ] ; // Look out for our future dive into Vectors and their various uses! while let Some ( dir ) = stack . last_mut ( ) { // Transpose says: Take that Option<Result> and turn it into a Result<Option>! match dir . next ( ) . transpose ( ) ? { None => { stack . pop ( ) ; } // A Some! But only if it's the kind of Some we want Some ( dir ) if dir . file_type ( ) . map_or ( false , | t | t . is_dir ( ) ) => { stack . push ( fs :: read_dir ( dir . path ( ) ) ? ) ; } Some ( file ) => files . push ( file . path ( ) ) , } } Ok ( files ) }
Recursively visits a path, returning a flattened list of ALL items
at or below the path
Iterative version
Recursively visits a path returning a flattened list of ALL items at or below the path Iterative version
dir
&Path