Skip to main content

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: &[u8]) -> Result<()>;
    fn exists(&self, path: &Path) -> bool;
    fn create_dir_all(&self, path: &Path) -> Result<()>;
    fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>;
    fn remove_file(&self, path: &Path) -> Result<()>;
    fn remove_dir_all(&self, path: &Path) -> Result<()>;
    fn is_dir(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
}
Expand description

A minimal file-system interface.

Prefer accepting a &dyn FileSystem in code that performs I/O so it can be tested without relying on std::fs.

Required Methods§

Source

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

Read the entire file at path into a UTF-8 string.

Source

fn write(&self, path: &Path, contents: &[u8]) -> Result<()>

Write contents to path, creating or truncating the file.

Source

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

Return true if path exists.

Source

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

Create all directories needed for path.

Source

fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>

Return the immediate children of path.

Source

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

Remove a file.

Source

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

Remove a directory and all of its contents.

Source

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

Return true if path is a directory.

Source

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

Return true if path is a file.

Implementors§