pub fn folder_contents<U: AsRef<OsStr>>(path: U) -> io::Result<Vec<Self>> {
        let path = PathBuf::from(&path);
        if !path.is_dir() {
            return Ok(Vec::new());
        }

        // Attempts to read from the .folder file.
        if let Some(Ok(folder)) = fs::read(path.join(".folder"))
            .ok()
            .map(|file| ron::from_str(&String::from_utf8(file).unwrap()))
        {
            Ok(folder)
        }
        // Otherwise, just manually goes through the files.
        else {
            let mut contents = Vec::new();

            for entry in fs::read_dir(path.clone())? {
                let path = &entry?.path();

                // Adds a new unloaded folder.
                if let Some(unloaded_folder) = Self::new_folder(path) {
                    contents.push(unloaded_folder);
                }
                // Adds a new file.
                else {
                    let ext = path.extension();
                    if ext == Some(OsStr::new("off")) || ext == Some(OsStr::new("ggb")) {
                        contents.push(Self::new_file(path));
                    }
                }
            }

            // We cache these contents for future use.
            if fs::write(path.join(".folder"), ron::to_string(&contents).unwrap()).is_ok() {
                println!(".folder file overwritten!");
            } else {
                println!(".folder file could not be overwritten!");
            }

            Ok(contents)
        }
    }
/// Reads a folder's data from the `.folder` file. If it doesn't exist, it
/// defaults to loading the folder's name and its data in alphabetical
/// order. If that also fails, it returns an `Err`.
Reads a folder's data from the `.folder` file. If it doesn't exist, it
defaults to loading the folder's name and its data in alphabetical
order. If that also fails, it returns an `Err`.
Reads a folder ' s data from the ` . folder ` file . If it doesn ' t exist it defaults to loading the folder ' s name and its data in alphabetical order . If that also fails it returns an ` Err ` .
pub fn folder_contents<U: AsRef<OsStr>>(path: U) -> io::Result<Vec<Self>> {
        let path = PathBuf::from(&path);
        if !path.is_dir() {
            return Ok(Vec::new());
        }
        // Attempts to read from the .folder file.
        if let Some(Ok(folder)) = fs::read(path.join(".folder"))
            .ok()
            .map(|file| ron::from_str(&String::from_utf8(file).unwrap()))
        {
            Ok(folder)
        }
        // Otherwise, just manually goes through the files.
        else {
            let mut contents = Vec::new();
            for entry in fs::read_dir(path.clone())? {
                let path = &entry?.path();
                // Adds a new unloaded folder.
                if let Some(unloaded_folder) = Self::new_folder(path) {
                    contents.push(unloaded_folder);
                }
                // Adds a new file.
                else {
                    let ext = path.extension();
                    if ext == Some(OsStr::new("off")) || ext == Some(OsStr::new("ggb")) {
                        contents.push(Self::new_file(path));
                    }
                }
            }
            // We cache these contents for future use.
            if fs::write(path.join(".folder"), ron::to_string(&contents).unwrap()).is_ok() {
                println!(".folder file overwritten!");
            } else {
                println!(".folder file could not be overwritten!");
            }
            Ok(contents)
        }
    }
pub fn folder_contents < U : AsRef < OsStr > > ( path : U ) -> io :: Result < Vec < Self > > { let path = PathBuf :: from ( & path ) ; if ! path . is_dir ( ) { return Ok ( Vec :: new ( ) ) ; } // Attempts to read from the .folder file. if let Some ( Ok ( folder ) ) = fs :: read ( path . join ( " " ) ) . ok ( ) . map ( | file | ron :: from_str ( & String :: from_utf8 ( file ) . unwrap ( ) ) ) { Ok ( folder ) } // Otherwise, just manually goes through the files. else { let mut contents = Vec :: new ( ) ; for entry in fs :: read_dir ( path . clone ( ) ) ? { let path = & entry ? . path ( ) ; // Adds a new unloaded folder. if let Some ( unloaded_folder ) = Self :: new_folder ( path ) { contents . push ( unloaded_folder ) ; } // Adds a new file. else { let ext = path . extension ( ) ; if ext == Some ( OsStr :: new ( " " ) ) || ext == Some ( OsStr :: new ( " " ) ) { contents . push ( Self :: new_file ( path ) ) ; } } } // We cache these contents for future use. if fs :: write ( path . join ( " " ) , ron :: to_string ( & contents ) . unwrap ( ) ) . is_ok ( ) { println ! ( " " ) ; } else { println ! ( " " ) ; } Ok ( contents ) } }
Reads a folder's data from the `.folder` file.
Reads a folder ' s data from the ` . folder ` file .
path
U
path
U