Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem: Send + Sync {
Show 13 methods // Required methods fn now(&self) -> SystemTime; fn exists(&self, path: &Path) -> bool; fn metadata(&self, path: &Path) -> Result<Metadata>; fn symlink_metadata(&self, path: &Path) -> Result<Metadata>; fn create_dir_all(&self, path: &Path) -> Result<()>; fn create_dir(&self, path: &Path) -> Result<()>; fn write(&self, path: &Path, data: &[u8]) -> Result<()>; fn write_to_string(&self, path: &Path, content: &str) -> Result<()>; fn read_to_string(&self, path: &Path) -> Result<String>; fn remove_file(&self, path: &Path) -> Result<()>; fn rename(&self, from: &Path, to: &Path) -> Result<()>; fn list_dir(&self, path: &Path) -> Result<Vec<PathBuf>>; fn remove_dir(&self, path: &Path) -> Result<()>;
}
Expand description

Filesystem abstraction boundary for command implementations.

Keeping this trait narrow makes it easy to write deterministic tests and allows alternative backends (e.g. in-memory fs) if command crates need it.

Required Methods§

Source

fn now(&self) -> SystemTime

Returns the current time in wall-clock format.

Source

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

Returns true when path exists (symlink-aware).

Source

fn metadata(&self, path: &Path) -> Result<Metadata>

Reads file metadata.

Reads symlink metadata.

Source

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

Creates a directory and all missing parent directories.

Source

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

Creates a directory.

Source

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

Writes raw bytes atomically (truncate + replace).

Source

fn write_to_string(&self, path: &Path, content: &str) -> Result<()>

Writes UTF-8 text.

Source

fn read_to_string(&self, path: &Path) -> Result<String>

Reads UTF-8 text.

Source

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

Removes a file.

Source

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

Renames/moves a path.

Source

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

Lists directory children as concrete paths.

Source

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

Removes an empty directory.

Implementors§