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§
Sourcefn create_dir(&self, path: &str) -> Result<()>
fn create_dir(&self, path: &str) -> Result<()>
Creates a directory at path
.
Sourcefn metadata(&self, path: &str) -> Result<Metadata>
fn metadata(&self, path: &str) -> Result<Metadata>
Returns the metadata for the file/folder at `path.
Sourcefn open_file_options(
&self,
path: &str,
options: &OpenOptions,
) -> Result<Box<dyn File>>
fn open_file_options( &self, path: &str, options: &OpenOptions, ) -> Result<Box<dyn File>>
Opens a file at path
with options options
.
Sourcefn read_dir(
&self,
path: &str,
) -> Result<Box<dyn Iterator<Item = Result<DirEntry>>>>
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
.
Sourcefn remove_dir(&self, path: &str) -> Result<()>
fn remove_dir(&self, path: &str) -> Result<()>
Removes the directory at path
.
Sourcefn remove_file(&self, path: &str) -> Result<()>
fn remove_file(&self, path: &str) -> Result<()>
Removes a file at path
.
Provided Methods§
Sourcefn create_dir_all(&self, path: &str) -> Result<()>
fn create_dir_all(&self, path: &str) -> Result<()>
Creates a directory path
and all of its parents.
Sourcefn create_file(&self, path: &str) -> Result<Box<dyn File>>
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.
Implementors§
impl FileSystem for MemoryFS
impl FileSystem for MountableFS
impl FileSystem for RocFS
impl FileSystem for MockFileSystem
A file system with a directory tree.