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§
Sourcefn read_to_string(&self, path: &Path) -> Result<String>
fn read_to_string(&self, path: &Path) -> Result<String>
Read the entire file at path into a UTF-8 string.
Sourcefn write(&self, path: &Path, contents: &[u8]) -> Result<()>
fn write(&self, path: &Path, contents: &[u8]) -> Result<()>
Write contents to path, creating or truncating the file.
Sourcefn create_dir_all(&self, path: &Path) -> Result<()>
fn create_dir_all(&self, path: &Path) -> Result<()>
Create all directories needed for path.
Sourcefn remove_file(&self, path: &Path) -> Result<()>
fn remove_file(&self, path: &Path) -> Result<()>
Remove a file.
Sourcefn remove_dir_all(&self, path: &Path) -> Result<()>
fn remove_dir_all(&self, path: &Path) -> Result<()>
Remove a directory and all of its contents.