FileSystem

Trait FileSystem 

Source
pub trait FileSystem: Send + Sync {
    // Required methods
    fn read_to_string(&self, path: &Path) -> Result<String>;
    fn write(&self, path: &Path, contents: &str) -> Result<()>;
    fn glob(&self, base: &Path, pattern: &str) -> Result<Vec<PathBuf>>;
    fn exists(&self, path: &Path) -> bool;
    fn create_dir_all(&self, path: &Path) -> Result<()>;
}
Expand description

Abstraction over filesystem operations for testability.

Required Methods§

Source

fn read_to_string(&self, path: &Path) -> Result<String>

Reads the contents of a file as a UTF-8 string.

Source

fn write(&self, path: &Path, contents: &str) -> Result<()>

Writes string contents to a file, creating parent directories as needed.

Source

fn glob(&self, base: &Path, pattern: &str) -> Result<Vec<PathBuf>>

Lists all files matching a glob pattern in a directory.

Source

fn exists(&self, path: &Path) -> bool

Checks if a path exists.

Source

fn create_dir_all(&self, path: &Path) -> Result<()>

Creates a directory and all parent directories.

Implementors§