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§
Sourcefn now(&self) -> SystemTime
fn now(&self) -> SystemTime
Returns the current time in wall-clock format.
Sourcefn symlink_metadata(&self, path: &Path) -> Result<Metadata>
fn symlink_metadata(&self, path: &Path) -> Result<Metadata>
Reads symlink metadata.
Sourcefn create_dir_all(&self, path: &Path) -> Result<()>
fn create_dir_all(&self, path: &Path) -> Result<()>
Creates a directory and all missing parent directories.
Sourcefn create_dir(&self, path: &Path) -> Result<()>
fn create_dir(&self, path: &Path) -> Result<()>
Creates a directory.
Sourcefn write(&self, path: &Path, data: &[u8]) -> Result<()>
fn write(&self, path: &Path, data: &[u8]) -> Result<()>
Writes raw bytes atomically (truncate + replace).
Sourcefn read_to_string(&self, path: &Path) -> Result<String>
fn read_to_string(&self, path: &Path) -> Result<String>
Reads UTF-8 text.
Sourcefn remove_file(&self, path: &Path) -> Result<()>
fn remove_file(&self, path: &Path) -> Result<()>
Removes a file.
Sourcefn list_dir(&self, path: &Path) -> Result<Vec<PathBuf>>
fn list_dir(&self, path: &Path) -> Result<Vec<PathBuf>>
Lists directory children as concrete paths.
Sourcefn remove_dir(&self, path: &Path) -> Result<()>
fn remove_dir(&self, path: &Path) -> Result<()>
Removes an empty directory.