Skip to main content

FsBackend

Trait FsBackend 

Source
pub trait FsBackend {
Show 13 methods // 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 ls<P: AsRef<Path>>( &self, path: P, ) -> Result<impl Iterator<Item = DirEntry>>; fn tree<P: AsRef<Path>>( &self, path: P, ) -> Result<impl Iterator<Item = DirEntry>>; 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§

Source

fn root(&self) -> &Path

Returns root path refer to the host file system.

Source

fn cwd(&self) -> &Path

Returns current working directory related to the vfs root.

Source

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.

Source

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

Returns true, if path exists.

Source

fn ls<P: AsRef<Path>>(&self, path: P) -> Result<impl Iterator<Item = DirEntry>>

Returns an iterator over directory entries. path is a directory, or CWD if None.

Source

fn tree<P: AsRef<Path>>( &self, path: P, ) -> Result<impl Iterator<Item = DirEntry>>

Returns a recursive iterator over the directory tree starting from a given path.

Source

fn mkdir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Creates directory and all it parents, if necessary.

Source

fn mkfile<P: AsRef<Path>>( &mut self, name: P, content: Option<&[u8]>, ) -> Result<()>

Creates new file in vfs.

Source

fn read<P: AsRef<Path>>(&self, path: P) -> Result<Vec<u8>>

Reads the entire contents of a file into a byte vector.

Source

fn write<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>

Writes bytes to an existing file, replacing its entire contents.

Source

fn append<P: AsRef<Path>>(&self, path: P, content: &[u8]) -> Result<()>

Appends bytes to the end of an existing file, preserving its old contents.

Source

fn rm<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Removes a file or directory at the specified path.

Source

fn cleanup(&mut self) -> bool

Removes all artifacts (dirs and files) in vfs, but preserve its root.

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.

Implementors§