Trait FileSystem

Source
pub trait FileSystem {
    // Required methods
    fn read_to_string(&self, path: &Path) -> Result<String>;
    fn write_all(&self, path: &Path, contents: &[u8]) -> Result<()>;
    fn create_dir_all(&self, path: &Path) -> Result<()>;
    fn remove_file(&self, path: &Path) -> Result<()>;
    fn remove_dir_all(&self, path: &Path) -> Result<()>;
    fn exists(&self, path: &Path) -> bool;
    fn is_dir(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
    fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
    fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>>;
}

Required Methods§

Source

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

Reads the entire contents of a file into a string.

§Errors

Returns an error if the file does not exist, cannot be read, or contains invalid UTF-8.

Source

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

Writes a slice of bytes to a file, creating the file if it does not exist.

§Errors

Returns an error if the file cannot be written to or created.

Source

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

Creates a directory and all of its parent components if they are missing.

§Errors

Returns an error if the directory cannot be created.

Source

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

Removes a file from the filesystem.

§Errors

Returns an error if the file does not exist or cannot be removed.

Source

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

Removes a directory and all of its contents.

§Errors

Returns an error if the directory does not exist or cannot be removed.

Source

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

Returns true if the path points to an existing entity.

Source

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

Returns true if the path exists and is pointing at a directory.

Source

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

Returns true if the path exists and is pointing at a regular file.

Source

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

Returns the canonical, absolute form of the path with all intermediate components normalized.

§Errors

Returns an error if the path does not exist or cannot be canonicalized.

Source

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

Returns a vector of all entries in a directory.

§Errors

Returns an error if the directory does not exist or cannot be read.

Implementors§