fn load_files_from_folder<T: serde::de::DeserializeOwned>(directory: PathBuf) -> Vec<(String, T)> {
    let mut result = Vec::new();
    info!(
        "Loading objects of type {} from directory {}",
        std::any::type_name::<T>(),
        directory.display(),
    );
    for dir_entry in fs::read_dir(directory).expect("Failed to read from directory") {
        let dir_entry = dir_entry.expect("Failed to read directory entry");
        if dir_entry
            .file_type()
            .expect("Failed to get file type")
            .is_file()
        {
            let file_path = dir_entry.path();

            match file_path.extension() {
                None => log::warn!(
                    "No file extension for file {}, skipping...",
                    file_path.display()
                ),
                Some(ext) => {
                    if ext == "ron" {
                        log::info!("Attempting to read file {}", file_path.display());
                        let mut file =
                            fs::File::open(file_path.clone()).expect("Failed to open file");
                        let mut buffer = String::new();
                        file.read_to_string(&mut buffer)
                            .expect("Failed to read from file");
                        let file_stem = file_path
                            .file_stem()
                            .expect("Failed to get file stem")
                            .to_str()
                            .unwrap()
                            .to_owned();

                        let parsed_file = {
                            if ext == "ron" {
                                match ron::de::from_str(&buffer) {
                                    Ok(x) => x,
                                    Err(e) => {
                                        log::error!("Failed to parse RON: {}, skipping...", e);
                                        continue;
                                    }
                                }
                            } else {
                                unreachable!("No parser for file format");
                            }
                        };
                        result.push((file_stem, parsed_file));
                    } else {
                        log::warn!("Unsupported file extension {:?}, skipping...", ext);
                        // TODO: display instead of debug
                    }
                }
            }
        }
    }
    result
}
/// Load all <name>.ron files from a given folder and parse them into type `T`.
Load all .ron files from a given folder and parse them into type `T`.
Load all . ron files from a given folder and parse them into type ` T ` .
fn load_files_from_folder<T: serde::de::DeserializeOwned>(directory: PathBuf) -> Vec<(String, T)> {
    let mut result = Vec::new();
    info!(
        "Loading objects of type {} from directory {}",
        std::any::type_name::<T>(),
        directory.display(),
    );
    for dir_entry in fs::read_dir(directory).expect("Failed to read from directory") {
        let dir_entry = dir_entry.expect("Failed to read directory entry");
        if dir_entry
            .file_type()
            .expect("Failed to get file type")
            .is_file()
        {
            let file_path = dir_entry.path();
            match file_path.extension() {
                None => log::warn!(
                    "No file extension for file {}, skipping...",
                    file_path.display()
                ),
                Some(ext) => {
                    if ext == "ron" {
                        log::info!("Attempting to read file {}", file_path.display());
                        let mut file =
                            fs::File::open(file_path.clone()).expect("Failed to open file");
                        let mut buffer = String::new();
                        file.read_to_string(&mut buffer)
                            .expect("Failed to read from file");
                        let file_stem = file_path
                            .file_stem()
                            .expect("Failed to get file stem")
                            .to_str()
                            .unwrap()
                            .to_owned();
                        let parsed_file = {
                            if ext == "ron" {
                                match ron::de::from_str(&buffer) {
                                    Ok(x) => x,
                                    Err(e) => {
                                        log::error!("Failed to parse RON: {}, skipping...", e);
                                        continue;
                                    }
                                }
                            } else {
                                unreachable!("No parser for file format");
                            }
                        };
                        result.push((file_stem, parsed_file));
                    } else {
                        log::warn!("Unsupported file extension {:?}, skipping...", ext);
                        // TODO: display instead of debug
                    }
                }
            }
        }
    }
    result
}
fn load_files_from_folder < T : serde :: de :: DeserializeOwned > ( directory : PathBuf ) -> Vec < ( String , T ) > { let mut result = Vec :: new ( ) ; info ! ( " " std any type_name T ( ) directory display ( ) ) ; for dir_entry in fs :: read_dir ( directory ) . expect ( " " ) { let dir_entry = dir_entry . expect ( " " ) ; if dir_entry . file_type ( ) . expect ( " " ) . is_file ( ) { let file_path = dir_entry . path ( ) ; match file_path . extension ( ) { None => log :: warn ! ( " " file_path display ( ) ) , Some ( ext ) => { if ext == " " { log :: info ! ( " " file_path display ( ) ) ; let mut file = fs :: File :: open ( file_path . clone ( ) ) . expect ( " " ) ; let mut buffer = String :: new ( ) ; file . read_to_string ( & mut buffer ) . expect ( " " ) ; let file_stem = file_path . file_stem ( ) . expect ( " " ) . to_str ( ) . unwrap ( ) . to_owned ( ) ; let parsed_file = { if ext == " " { match ron :: de :: from_str ( & buffer ) { Ok ( x ) => x , Err ( e ) => { log :: error ! ( " " e ) ; continue ; } } } else { unreachable ! ( " " ) ; } } ; result . push ( ( file_stem , parsed_file ) ) ; } else { log :: warn ! ( " " ext ) ; // TODO: display instead of debug } } } } } result }
Load all <name>.ron files from a given folder and parse them into type `T`.
Load all <name > . ron files from a given folder and parse them into type ` T ` .
directory
PathBuf
directory
PathBuf