pub trait Fs: Send + Sync {
Show 18 methods
// Required methods
fn stat(&self, path: &Path) -> Result<FsMetadata>;
fn lstat(&self, path: &Path) -> Result<FsMetadata>;
fn open_read(&self, path: &Path) -> Result<Box<dyn Read + Send + Sync>>;
fn read_file(&self, path: &Path) -> Result<Vec<u8>>;
fn read_to_string(&self, path: &Path) -> Result<String>;
fn write_file(&self, path: &Path, contents: &[u8]) -> Result<()>;
fn mkdir_all(&self, path: &Path) -> Result<()>;
fn symlink(&self, original: &Path, link: &Path) -> Result<()>;
fn readlink(&self, path: &Path) -> Result<PathBuf>;
fn remove_file(&self, path: &Path) -> Result<()>;
fn remove_dir_all(&self, path: &Path) -> Result<()>;
fn exists(&self, path: &Path) -> bool;
fn is_symlink(&self, path: &Path) -> bool;
fn is_dir(&self, path: &Path) -> bool;
fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>;
fn rename(&self, from: &Path, to: &Path) -> Result<()>;
fn copy_file(&self, from: &Path, to: &Path) -> Result<()>;
fn set_permissions(&self, path: &Path, mode: u32) -> Result<()>;
}Expand description
Filesystem abstraction.
All dodot code accesses the filesystem through this trait so that:
- Tests can use isolated temp directories with a real implementation
- Every
io::Erroris wrapped with the path that caused it
Use &dyn Fs (trait objects) throughout the codebase. The operations
are I/O-bound so dynamic dispatch costs nothing meaningful, and generics
would infect every type signature.
Required Methods§
Sourcefn stat(&self, path: &Path) -> Result<FsMetadata>
fn stat(&self, path: &Path) -> Result<FsMetadata>
Returns metadata for the path, following symlinks.
Sourcefn lstat(&self, path: &Path) -> Result<FsMetadata>
fn lstat(&self, path: &Path) -> Result<FsMetadata>
Returns metadata for the path without following symlinks.
Sourcefn open_read(&self, path: &Path) -> Result<Box<dyn Read + Send + Sync>>
fn open_read(&self, path: &Path) -> Result<Box<dyn Read + Send + Sync>>
Opens the file for reading in a streaming fashion.
Errors that occur while opening the file are returned through this
method’s Result and include path context. Once opened, the
returned reader is a raw std::io::Read, so any later read()
errors are reported as plain std::io::Error values and are not
automatically wrapped with the path.
Sourcefn read_to_string(&self, path: &Path) -> Result<String>
fn read_to_string(&self, path: &Path) -> Result<String>
Reads the entire file as a UTF-8 string.
Sourcefn write_file(&self, path: &Path, contents: &[u8]) -> Result<()>
fn write_file(&self, path: &Path, contents: &[u8]) -> Result<()>
Writes contents to path, creating or truncating the file.
Sourcefn symlink(&self, original: &Path, link: &Path) -> Result<()>
fn symlink(&self, original: &Path, link: &Path) -> Result<()>
Creates a symbolic link at link pointing to original.
Sourcefn remove_file(&self, path: &Path) -> Result<()>
fn remove_file(&self, path: &Path) -> Result<()>
Removes a file or symlink (not a directory).
Sourcefn remove_dir_all(&self, path: &Path) -> Result<()>
fn remove_dir_all(&self, path: &Path) -> Result<()>
Removes a directory and all of its contents.
Sourcefn is_symlink(&self, path: &Path) -> bool
fn is_symlink(&self, path: &Path) -> bool
Returns true if path is a symlink (does not follow).