pub fn fs_to_tree<P: AsRef<Path>>(
    options: &FsOptions<P>,
) -> (Arena<FsEntry>, NodeId, usize, usize) {
    let mut walk = PutBack::new(get_walker(&options));

    let mut tree = Arena::<FsEntry>::new();
    let root = match walk.next() {
        Some(Ok(de)) => tree.new_node(root_to_fsentry(&options.root, de)),
        Some(Err(ignore::Error::WithPath { path, err })) => {
            if let ignore::Error::Io(e) = err.deref() {
                if e.kind() == io::ErrorKind::NotFound {
                    eprintln!("Path \"{}\" was not found", path.display());
                } else {
                    eprintln!(
                        "An error occurred getting {}: {:?}",
                        path.display(),
                        e.kind()
                    );
                }
            } else {
                eprintln!("Could not get {}: {:?}", path.display(), err);
            }

            ::std::process::exit(1);
        }
        Some(Err(_)) => {
            eprintln!("An unexpected error occurred getting the root!");
            ::std::process::exit(2);
        }
        None => {
            unreachable!("Should always get a first walk entry");
        }
    };

    let mut n_files = 0;
    let mut n_dirs = 0;
    let mut curr = root;
    while let Some(res) = walk.next() {
        let mut fse = match res {
            Ok(de) => {
                if is_or_points_to_dir(&de) {
                    n_dirs += 1;
                } else if options.only_dirs {
                    continue;
                } else {
                    n_files += 1;
                }

                de_to_fsentry(de)
            }
            Err(_) => {
                panic!("This error should have been handled in `determine_place_in_tree` in the previous iteration.");
            }
        };

        match determine_place_in_tree(&mut walk, &mut fse, options.only_dirs) {
            DepthChange::NextIsFirst => {
                curr = add_child_to_tree(&mut tree, curr, fse);
            }
            DepthChange::Isnt => {
                add_child_to_tree(&mut tree, curr, fse);
            }
            DepthChange::Last(d) => {
                add_child_to_tree(&mut tree, curr, fse);
                for _ in 0..d {
                    curr = tree[curr].parent().expect("The node should have a parent");
                }
            }
        }
    }

    (tree, root, n_files, n_dirs)
}
/// Collect an Arena representation of the file system.
///
/// Returns an Arena-tree, its root, and the number of files
/// and directories in it.
Collect an Arena representation of the file system.
Returns an Arena-tree, its root, and the number of files
and directories in it.
Collect an Arena representation of the file system . Returns an Arena - tree its root and the number of files and directories in it .
pub fn fs_to_tree<P: AsRef<Path>>(
    options: &FsOptions<P>,
) -> (Arena<FsEntry>, NodeId, usize, usize) {
    let mut walk = PutBack::new(get_walker(&options));
    let mut tree = Arena::<FsEntry>::new();
    let root = match walk.next() {
        Some(Ok(de)) => tree.new_node(root_to_fsentry(&options.root, de)),
        Some(Err(ignore::Error::WithPath { path, err })) => {
            if let ignore::Error::Io(e) = err.deref() {
                if e.kind() == io::ErrorKind::NotFound {
                    eprintln!("Path \"{}\" was not found", path.display());
                } else {
                    eprintln!(
                        "An error occurred getting {}: {:?}",
                        path.display(),
                        e.kind()
                    );
                }
            } else {
                eprintln!("Could not get {}: {:?}", path.display(), err);
            }
            ::std::process::exit(1);
        }
        Some(Err(_)) => {
            eprintln!("An unexpected error occurred getting the root!");
            ::std::process::exit(2);
        }
        None => {
            unreachable!("Should always get a first walk entry");
        }
    };
    let mut n_files = 0;
    let mut n_dirs = 0;
    let mut curr = root;
    while let Some(res) = walk.next() {
        let mut fse = match res {
            Ok(de) => {
                if is_or_points_to_dir(&de) {
                    n_dirs += 1;
                } else if options.only_dirs {
                    continue;
                } else {
                    n_files += 1;
                }
                de_to_fsentry(de)
            }
            Err(_) => {
                panic!("This error should have been handled in `determine_place_in_tree` in the previous iteration.");
            }
        };
        match determine_place_in_tree(&mut walk, &mut fse, options.only_dirs) {
            DepthChange::NextIsFirst => {
                curr = add_child_to_tree(&mut tree, curr, fse);
            }
            DepthChange::Isnt => {
                add_child_to_tree(&mut tree, curr, fse);
            }
            DepthChange::Last(d) => {
                add_child_to_tree(&mut tree, curr, fse);
                for _ in 0..d {
                    curr = tree[curr].parent().expect("The node should have a parent");
                }
            }
        }
    }
    (tree, root, n_files, n_dirs)
}
pub fn fs_to_tree < P : AsRef < Path > > ( options : & FsOptions < P > , ) -> ( Arena < FsEntry > , NodeId , usize , usize ) { let mut walk = PutBack :: new ( get_walker ( & options ) ) ; let mut tree = Arena :: < FsEntry > :: new ( ) ; let root = match walk . next ( ) { Some ( Ok ( de ) ) => tree . new_node ( root_to_fsentry ( & options . root , de ) ) , Some ( Err ( ignore :: Error :: WithPath { path , err } ) ) => { if let ignore :: Error :: Io ( e ) = err . deref ( ) { if e . kind ( ) == io :: ErrorKind :: NotFound { eprintln ! ( " \" \" " path display ( ) ) ; } else { eprintln ! ( " " path display ( ) e kind ( ) ) ; } } else { eprintln ! ( " " path display ( ) err ) ; } :: std :: process :: exit ( 1 ) ; } Some ( Err ( _ ) ) => { eprintln ! ( " " ) ; :: std :: process :: exit ( 2 ) ; } None => { unreachable ! ( " " ) ; } } ; let mut n_files = 0 ; let mut n_dirs = 0 ; let mut curr = root ; while let Some ( res ) = walk . next ( ) { let mut fse = match res { Ok ( de ) => { if is_or_points_to_dir ( & de ) { n_dirs += 1 ; } else if options . only_dirs { continue ; } else { n_files += 1 ; } de_to_fsentry ( de ) } Err ( _ ) => { panic ! ( " " ) ; } } ; match determine_place_in_tree ( & mut walk , & mut fse , options . only_dirs ) { DepthChange :: NextIsFirst => { curr = add_child_to_tree ( & mut tree , curr , fse ) ; } DepthChange :: Isnt => { add_child_to_tree ( & mut tree , curr , fse ) ; } DepthChange :: Last ( d ) => { add_child_to_tree ( & mut tree , curr , fse ) ; for _ in 0 .. d { curr = tree [ curr ] . parent ( ) . expect ( " " ) ; } } } } ( tree , root , n_files , n_dirs ) }
Collect an Arena representation of the file system.
Collect an Arena representation of the file system .
options
&FsOptions<P>
options
&FsOptions<P>