Skip to main content

Vfs

Trait Vfs 

Source
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§

Source

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.

Source

fn open(&self, path: &Path) -> Result<u64>

Opens an existing path and returns its byte length.

Source

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.

Source

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

Reads an entire file.

Source

fn read_range(&self, path: &Path, offset: u64, length: usize) -> Result<Vec<u8>>

Reads at most length bytes beginning at offset.

Source

fn write(&self, path: &Path, bytes: &[u8]) -> Result<()>

Creates or truncates a file and writes all bytes.

Source

fn open_append(&self, path: &Path) -> Result<Box<dyn VfsFile>>

Opens or creates one file for handle-oriented append-only writes.

Source

fn rename(&self, from: &Path, to: &Path) -> Result<()>

Atomically renames one path over another according to platform semantics.

Source

fn sync(&self, path: &Path, kind: SyncKind) -> Result<()>

Synchronizes a file or directory using an explicit platform primitive.

Source

fn list(&self, directory: &Path) -> Result<Vec<PathBuf>>

Lists direct children of a directory.

Source

fn for_each_direct_child( &self, directory: &Path, visitor: &mut dyn FnMut(&Path) -> Result<()>, ) -> Result<()>

Visits direct children one at a time without collecting the directory.

Source

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

Deletes one file.

Provided Methods§

Source

fn create_directory(&self, _path: &Path) -> Result<()>

Exclusively creates one directory. Existing paths are preserved and reported as AlreadyExists; no ancestor is adopted implicitly.

Source

fn remove_directory(&self, _path: &Path) -> Result<()>

Removes one empty directory. A non-empty directory is an error.

Source

fn truncate(&self, _path: &Path, _length: u64) -> Result<()>

Removes a suffix without copying the retained file bytes.

Source

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".

Implementors§

Source§

impl Vfs for StdVfs

Source§

impl<V: Vfs> Vfs for CountingVfs<V>