pub trait Fs {
// Required methods
fn create_dir_all(&self, path: &Path) -> Result<(), SessionError>;
fn exists(&self, path: &Path) -> bool;
fn read(&self, path: &Path) -> Result<Vec<u8>, SessionError>;
fn write(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>;
fn append(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>;
fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>, SessionError>;
fn rename(&self, from: &Path, to: &Path) -> Result<(), SessionError>;
fn remove(&self, path: &Path) -> Result<(), SessionError>;
}Expand description
Abstraction over filesystem operations used by zenith-session.
Implementations must satisfy the following contract:
- All directory and file listings are returned sorted for deterministic iteration across platforms.
writemust fail with an error when the parent directory does not exist (to faithfully model real OS behaviour so fakes don’t silently false-pass tests that forgetcreate_dir_all).
Required Methods§
Sourcefn create_dir_all(&self, path: &Path) -> Result<(), SessionError>
fn create_dir_all(&self, path: &Path) -> Result<(), SessionError>
Create path and all missing ancestors, like mkdir -p.
Sourcefn read(&self, path: &Path) -> Result<Vec<u8>, SessionError>
fn read(&self, path: &Path) -> Result<Vec<u8>, SessionError>
Read the entire contents of the file at path.
Sourcefn write(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>
fn write(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>
Write data to path, replacing any existing content.
Returns an error if the parent directory does not exist.
Sourcefn append(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>
fn append(&self, path: &Path, data: &[u8]) -> Result<(), SessionError>
Append data to the file at path, creating it if absent. Like write,
it errors if the parent directory does not exist.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".