Skip to main content

VirtualFs

Trait VirtualFs 

Source
pub trait VirtualFs: Send + Sync {
Show 23 methods // Required methods fn read_file(&self, path: &Path) -> Result<Vec<u8>, VfsError>; fn write_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>; fn append_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>; fn remove_file(&self, path: &Path) -> Result<(), VfsError>; fn mkdir(&self, path: &Path) -> Result<(), VfsError>; fn mkdir_p(&self, path: &Path) -> Result<(), VfsError>; fn readdir(&self, path: &Path) -> Result<Vec<DirEntry>, VfsError>; fn remove_dir(&self, path: &Path) -> Result<(), VfsError>; fn remove_dir_all(&self, path: &Path) -> Result<(), VfsError>; fn exists(&self, path: &Path) -> bool; fn stat(&self, path: &Path) -> Result<Metadata, VfsError>; fn lstat(&self, path: &Path) -> Result<Metadata, VfsError>; fn chmod(&self, path: &Path, mode: u32) -> Result<(), VfsError>; fn utimes(&self, path: &Path, mtime: SystemTime) -> Result<(), VfsError>; fn symlink(&self, target: &Path, link: &Path) -> Result<(), VfsError>; fn hardlink(&self, src: &Path, dst: &Path) -> Result<(), VfsError>; fn readlink(&self, path: &Path) -> Result<PathBuf, VfsError>; fn canonicalize(&self, path: &Path) -> Result<PathBuf, VfsError>; fn copy(&self, src: &Path, dst: &Path) -> Result<(), VfsError>; fn rename(&self, src: &Path, dst: &Path) -> Result<(), VfsError>; fn glob(&self, pattern: &str, cwd: &Path) -> Result<Vec<PathBuf>, VfsError>; fn deep_clone(&self) -> Arc<dyn VirtualFs>; // Provided method fn glob_with_opts( &self, pattern: &str, cwd: &Path, _opts: &GlobOptions, ) -> Result<Vec<PathBuf>, VfsError> { ... }
}
Expand description

Trait abstracting all filesystem operations.

All methods take &self — implementations use interior mutability. All paths are expected to be absolute.

Required Methods§

Source

fn read_file(&self, path: &Path) -> Result<Vec<u8>, VfsError>

Source

fn write_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>

Source

fn append_file(&self, path: &Path, content: &[u8]) -> Result<(), VfsError>

Source

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

Source

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

Source

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

Source

fn readdir(&self, path: &Path) -> Result<Vec<DirEntry>, VfsError>

Source

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

Source

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

Source

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

Source

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

Source

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

Source

fn chmod(&self, path: &Path, mode: u32) -> Result<(), VfsError>

Source

fn utimes(&self, path: &Path, mtime: SystemTime) -> Result<(), VfsError>

Source

fn canonicalize(&self, path: &Path) -> Result<PathBuf, VfsError>

Source

fn copy(&self, src: &Path, dst: &Path) -> Result<(), VfsError>

Source

fn rename(&self, src: &Path, dst: &Path) -> Result<(), VfsError>

Source

fn glob(&self, pattern: &str, cwd: &Path) -> Result<Vec<PathBuf>, VfsError>

Source

fn deep_clone(&self) -> Arc<dyn VirtualFs>

Create an independent deep copy for subshell isolation.

Subshells ( ... ) and command substitutions $(...) need an isolated filesystem so their mutations don’t leak back to the parent. Each backend decides what “independent copy” means:

  • InMemoryFs: clones the entire tree
  • OverlayFs: clones the upper layer and whiteouts; lower is shared
  • ReadWriteFs: no isolation (returns Arc::clone — writes hit real FS)
  • MountableFs: recursively deep-clones each mount

Provided Methods§

Source

fn glob_with_opts( &self, pattern: &str, cwd: &Path, _opts: &GlobOptions, ) -> Result<Vec<PathBuf>, VfsError>

Glob expansion with shopt-controlled options (dotglob, nocaseglob, globstar).

The default implementation ignores options and delegates to glob(). Override in backends that can honor the options.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§