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§
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>
Sourcefn deep_clone(&self) -> Arc<dyn VirtualFs>
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§
Sourcefn glob_with_opts(
&self,
pattern: &str,
cwd: &Path,
_opts: &GlobOptions,
) -> Result<Vec<PathBuf>, VfsError>
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.