pub trait FsBackend {
// Required methods
fn root(&self) -> &Path;
fn cwd(&self) -> &Path;
fn cd<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn exists<P: AsRef<Path>>(&self, path: P) -> bool;
fn mkdir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn mkfile<P: AsRef<Path>>(
&mut self,
name: P,
content: Option<&[u8]>,
) -> Result<()>;
fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>;
fn write<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>;
fn append<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>;
fn rm<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn cleanup(&mut self) -> bool;
}Expand description
FsBackend defines a common API for all virtual file systems (vfs) in the crate.
Some functions here use path as a parameter or return value.
In all cases, path will refer to the virtual file system. The exception
is the root() function, which returns the path in the host file system.
Required Methods§
Sourcefn cd<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
fn cd<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Changes the current working directory.
path can be in relative or absolute form, but in both cases it must exist in vfs.
Error returns in case the path is not exist.
Sourcefn mkdir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
fn mkdir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Creates directory and all it parents, if necessary.
Sourcefn mkfile<P: AsRef<Path>>(
&mut self,
name: P,
content: Option<&[u8]>,
) -> Result<()>
fn mkfile<P: AsRef<Path>>( &mut self, name: P, content: Option<&[u8]>, ) -> Result<()>
Creates new file in vfs.
Sourcefn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>
fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>
Reads the entire contents of a file into a byte vector.
Sourcefn write<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>
fn write<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>
Writes bytes to an existing file, replacing its entire contents.
Sourcefn append<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>
fn append<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>
Appends bytes to the end of an existing file, preserving its old contents.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.