pub trait Vfs: Send + Sync {
Show 16 methods
// Required methods
fn ensure_directory(&self, path: &Path, create: bool) -> Result<bool>;
fn open(&self, path: &Path) -> Result<u64>;
fn open_for_map(&self, path: &Path) -> Result<File>;
fn read(&self, path: &Path) -> Result<Vec<u8>>;
fn read_range(
&self,
path: &Path,
offset: u64,
length: usize,
) -> Result<Vec<u8>>;
fn write(&self, path: &Path, bytes: &[u8]) -> Result<()>;
fn open_append(&self, path: &Path) -> Result<Box<dyn VfsFile>>;
fn rename(&self, from: &Path, to: &Path) -> Result<()>;
fn sync(&self, path: &Path, kind: SyncKind) -> Result<()>;
fn list(&self, directory: &Path) -> Result<Vec<PathBuf>>;
fn for_each_direct_child(
&self,
directory: &Path,
visitor: &mut dyn FnMut(&Path) -> Result<()>,
) -> Result<()>;
fn delete(&self, path: &Path) -> Result<()>;
// Provided methods
fn create_directory(&self, _path: &Path) -> Result<()> { ... }
fn remove_directory(&self, _path: &Path) -> Result<()> { ... }
fn truncate(&self, _path: &Path, _length: u64) -> Result<()> { ... }
fn create_new(&self, _path: &Path, _bytes: &[u8]) -> Result<()> { ... }
}Expand description
Minimal synchronous filesystem operations used by persisted commits.
Required Methods§
Sourcefn ensure_directory(&self, path: &Path, create: bool) -> Result<bool>
fn ensure_directory(&self, path: &Path, create: bool) -> Result<bool>
Admits a store directory, creating missing ancestors when requested, and reports whether the resulting path is a directory.
Sourcefn open_for_map(&self, path: &Path) -> Result<File>
fn open_for_map(&self, path: &Path) -> Result<File>
Opens an existing path as an owned file suitable for memory mapping.
Test filesystems without a native file descriptor return
std::io::ErrorKind::Unsupported. Consequently MemoryVfs,
CrashVfs, and memory-backed FaultVfs images cannot publish or reopen
a sealed segment; use a path-backed VFS when exercising that lifecycle.
Sourcefn read_range(&self, path: &Path, offset: u64, length: usize) -> Result<Vec<u8>>
fn read_range(&self, path: &Path, offset: u64, length: usize) -> Result<Vec<u8>>
Reads at most length bytes beginning at offset.
Sourcefn write(&self, path: &Path, bytes: &[u8]) -> Result<()>
fn write(&self, path: &Path, bytes: &[u8]) -> Result<()>
Creates or truncates a file and writes all bytes.
Sourcefn open_append(&self, path: &Path) -> Result<Box<dyn VfsFile>>
fn open_append(&self, path: &Path) -> Result<Box<dyn VfsFile>>
Opens or creates one file for handle-oriented append-only writes.
Sourcefn rename(&self, from: &Path, to: &Path) -> Result<()>
fn rename(&self, from: &Path, to: &Path) -> Result<()>
Atomically renames one path over another according to platform semantics.
Sourcefn sync(&self, path: &Path, kind: SyncKind) -> Result<()>
fn sync(&self, path: &Path, kind: SyncKind) -> Result<()>
Synchronizes a file or directory using an explicit platform primitive.
Provided Methods§
Sourcefn create_directory(&self, _path: &Path) -> Result<()>
fn create_directory(&self, _path: &Path) -> Result<()>
Exclusively creates one directory. Existing paths are preserved and
reported as AlreadyExists; no ancestor is adopted implicitly.
Sourcefn remove_directory(&self, _path: &Path) -> Result<()>
fn remove_directory(&self, _path: &Path) -> Result<()>
Removes one empty directory. A non-empty directory is an error.
Sourcefn truncate(&self, _path: &Path, _length: u64) -> Result<()>
fn truncate(&self, _path: &Path, _length: u64) -> Result<()>
Removes a suffix without copying the retained file bytes.
Sourcefn create_new(&self, _path: &Path, _bytes: &[u8]) -> Result<()>
fn create_new(&self, _path: &Path, _bytes: &[u8]) -> Result<()>
Exclusively creates a file and writes every byte without replacing any existing path. A failed write may leave a new partial file; callers must retain it as an uncommitted artifact until safe cleanup is established. Filesystems without atomic exclusive creation fail explicitly.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".