Trait FileSystem

Source
pub trait FileSystem {
    // Required methods
    fn create_dir(&self, path: &str) -> Result<()>;
    fn metadata(&self, path: &str) -> Result<Metadata>;
    fn open_file_options(
        &self,
        path: &str,
        options: &OpenOptions,
    ) -> Result<Box<dyn File>>;
    fn read_dir(
        &self,
        path: &str,
    ) -> Result<Box<dyn Iterator<Item = Result<DirEntry>>>>;
    fn remove_dir(&self, path: &str) -> Result<()>;
    fn remove_file(&self, path: &str) -> Result<()>;

    // Provided methods
    fn create_dir_all(&self, path: &str) -> Result<()> { ... }
    fn create_file(&self, path: &str) -> Result<Box<dyn File>> { ... }
    fn exists(&self, path: &str) -> Result<bool> { ... }
    fn open_file(&self, path: &str) -> Result<Box<dyn File>> { ... }
}
Expand description

A file system with a directory tree.

Required Methods§

Source

fn create_dir(&self, path: &str) -> Result<()>

Creates a directory at path.

Source

fn metadata(&self, path: &str) -> Result<Metadata>

Returns the metadata for the file/folder at `path.

Source

fn open_file_options( &self, path: &str, options: &OpenOptions, ) -> Result<Box<dyn File>>

Opens a file at path with options options.

Source

fn read_dir( &self, path: &str, ) -> Result<Box<dyn Iterator<Item = Result<DirEntry>>>>

Lists the files and folders contained in the directory denoted by path.

Source

fn remove_dir(&self, path: &str) -> Result<()>

Removes the directory at path.

Source

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

Removes a file at path.

Provided Methods§

Source

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

Creates a directory path and all of its parents.

Source

fn create_file(&self, path: &str) -> Result<Box<dyn File>>

Creates a file at path in write mode. The file will be opened in truncate mode, so all contents will be overwritten. If this is not desirable, use open_file directly.

Source

fn exists(&self, path: &str) -> Result<bool>

Returns Ok(true) or Ok(false) if a file or folder at path does or does not exist, and Err(_) if the presence cannot be verified.

Source

fn open_file(&self, path: &str) -> Result<Box<dyn File>>

Opens a file at path for reading.

Implementors§

Source§

impl FileSystem for MemoryFS

Source§

impl FileSystem for MountableFS

Source§

impl FileSystem for RocFS

Source§

impl FileSystem for MockFileSystem

A file system with a directory tree.

Source§

impl FileSystem for TarFS

Source§

impl<R: Read + Seek> FileSystem for ZipFS<R>

Source§

impl<R: PathResolver> FileSystem for PhysicalFSImpl<R>