fn collect_subdirs<F, T>(dir: &Path, transform: F) -> Result<Vec<T>, LayoutError>
where
    F: Fn(&str) -> T,
{
    let mut ids = Vec::new();

    if !dir.exists() {
        return Ok(ids);
    }

    let entries = dir.read_dir().map_err(|err| LayoutError::IoError {
        path: dir.to_path_buf(),
        message: "Failed to read directory".to_string(),
        io_err: err,
    })?;

    for entry in entries {
        let dir = entry.map_err(|err| LayoutError::IoError {
            path: dir.to_path_buf(),
            message: "Failed to get dir entry".to_string(),
            io_err: err,
        })?;

        if let Some(file_name) = dir.file_name().to_str() {
            ids.push(transform(file_name));
        }
    }
    Ok(ids)
}
/// Collects all the direct children of the specified directory into a
/// vector and applies the provided transformation to them.  The names
/// are assumed to be hex numbers.
Collects all the direct children of the specified directory into a
vector and applies the provided transformation to them.  The names
are assumed to be hex numbers.
Collects all the direct children of the specified directory into a vector and applies the provided transformation to them . The names are assumed to be hex numbers .
fn collect_subdirs<F, T>(dir: &Path, transform: F) -> Result<Vec<T>, LayoutError>
where
    F: Fn(&str) -> T,
{
    let mut ids = Vec::new();
    if !dir.exists() {
        return Ok(ids);
    }
    let entries = dir.read_dir().map_err(|err| LayoutError::IoError {
        path: dir.to_path_buf(),
        message: "Failed to read directory".to_string(),
        io_err: err,
    })?;
    for entry in entries {
        let dir = entry.map_err(|err| LayoutError::IoError {
            path: dir.to_path_buf(),
            message: "Failed to get dir entry".to_string(),
            io_err: err,
        })?;
        if let Some(file_name) = dir.file_name().to_str() {
            ids.push(transform(file_name));
        }
    }
    Ok(ids)
}
fn collect_subdirs < F , T > ( dir : & Path , transform : F ) -> Result < Vec < T > , LayoutError > where F : Fn ( & str ) -> T , { let mut ids = Vec :: new ( ) ; if ! dir . exists ( ) { return Ok ( ids ) ; } let entries = dir . read_dir ( ) . map_err ( | err | LayoutError :: IoError { path : dir . to_path_buf ( ) , message : " " . to_string ( ) , io_err : err , } ) ? ; for entry in entries { let dir = entry . map_err ( | err | LayoutError :: IoError { path : dir . to_path_buf ( ) , message : " " . to_string ( ) , io_err : err , } ) ? ; if let Some ( file_name ) = dir . file_name ( ) . to_str ( ) { ids . push ( transform ( file_name ) ) ; } } Ok ( ids ) }
Collects all the direct children of the specified directory into a
vector and applies the provided transformation to them.
Collects all the direct children of the specified directory into a vector and applies the provided transformation to them .
dir
&Path
transform
F
dir
&Path
transform
F