Skip to main content

FileSystemProvider

Trait FileSystemProvider 

Source
pub trait FileSystemProvider: Send + Sync {
    // Required methods
    fn read(&self, path: &Path) -> Result<Vec<u8>>;
    fn write(&self, path: &Path, data: &[u8]) -> Result<()>;
    fn append(&self, path: &Path, data: &[u8]) -> Result<()>;
    fn exists(&self, path: &Path) -> bool;
    fn remove(&self, path: &Path) -> Result<()>;
    fn list_dir(&self, path: &Path) -> Result<Vec<PathEntry>>;
    fn metadata(&self, path: &Path) -> Result<FileMetadata>;
    fn create_dir_all(&self, path: &Path) -> Result<()>;
}
Expand description

Trait for all filesystem operations used by the Shape stdlib.

Implementations include:

  • RealFileSystem — delegates to std::fs
  • PolicyEnforcedFs — wraps another provider with permission checks
  • VirtualFilesystem (in virtual_fs.rs) — in-memory sandbox

Required Methods§

Source

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

Read the entire contents of a file.

Source

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

Write data to a file, creating or truncating as needed.

Source

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

Append data to a file.

Source

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

Check whether a path exists.

Source

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

Remove a file.

Source

fn list_dir(&self, path: &Path) -> Result<Vec<PathEntry>>

List entries in a directory.

Source

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

Query metadata for a path.

Source

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

Recursively create directories.

Implementors§