Skip to main content

Fs

Trait Fs 

Source
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.
  • write must 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 forget create_dir_all).

Required Methods§

Source

fn create_dir_all(&self, path: &Path) -> Result<(), SessionError>

Create path and all missing ancestors, like mkdir -p.

Source

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

Return true if path exists (file or directory).

Source

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

Read the entire contents of the file at path.

Source

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.

Source

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.

Source

fn read_dir(&self, path: &Path) -> Result<Vec<PathBuf>, SessionError>

List immediate children (files and directories) of path, sorted for deterministic iteration.

Source

fn rename(&self, from: &Path, to: &Path) -> Result<(), SessionError>

Rename / move from to to.

Source

fn remove(&self, path: &Path) -> Result<(), SessionError>

Remove a file or directory tree at path.

Tries remove_file first; on failure tries remove_dir_all. This keeps the API simple: callers do not need to know whether path is a file or a directory.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Fs for MemFs

Source§

impl Fs for OsFs