pub trait FsBackend {
Show 16 methods
// Required methods
fn root(&self) -> &Path;
fn cwd(&self) -> &Path;
fn to_host<P: AsRef<Path>>(&self, inner_path: P) -> Result<PathBuf>;
fn cd<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn exists<P: AsRef<Path>>(&self, path: P) -> bool;
fn is_dir<P: AsRef<Path>>(&self, path: P) -> Result<bool>;
fn is_file<P: AsRef<Path>>(&self, path: P) -> Result<bool>;
fn ls<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = &Path>>;
fn tree<P: AsRef<Path>>(
&self,
path: P,
) -> Result<impl Iterator<Item = &Path>>;
fn mkdir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>;
fn mkfile<P: AsRef<Path>>(
&mut self,
file_path: P,
content: Option<&[u8]>,
) -> Result<()>;
fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>;
fn write<P: AsRef<Path>>(&mut self, path: P, content: &[u8]) -> Result<()>;
fn append<P: AsRef<Path>>(&mut 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 to_host<P: AsRef<Path>>(&self, inner_path: P) -> Result<PathBuf>
fn to_host<P: AsRef<Path>>(&self, inner_path: P) -> Result<PathBuf>
Returns the path on the host system that matches the specified internal path.
inner_pathmust exist in VFS
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 ls<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = &Path>>
fn ls<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = &Path>>
Returns an iterator over directory entries.
path is a directory, or CWD if None.
Sourcefn tree<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = &Path>>
fn tree<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = &Path>>
Returns a recursive iterator over the directory tree starting from a given path.
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,
file_path: P,
content: Option<&[u8]>,
) -> Result<()>
fn mkfile<P: AsRef<Path>>( &mut self, file_path: 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>>(&mut self, path: P, content: &[u8]) -> Result<()>
fn write<P: AsRef<Path>>(&mut self, path: P, content: &[u8]) -> Result<()>
Writes bytes to an existing file, replacing its entire contents.
Sourcefn append<P: AsRef<Path>>(&mut self, path: P, content: &[u8]) -> Result<()>
fn append<P: AsRef<Path>>(&mut 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.