pub trait FileSystem:
Send
+ Sync
+ Debug {
// Required methods
fn read(&self, path: &Path) -> Result<Arc<str>, LoadError>;
fn exists(&self, path: &Path) -> bool;
fn is_encrypted(&self, path: &Path) -> bool;
fn normalize(&self, path: &Path) -> PathBuf;
// Provided methods
fn supports_parallel_read(&self) -> bool { ... }
fn glob(&self, pattern: &str) -> Result<Vec<PathBuf>, String> { ... }
fn decrypt(&self, path: &Path) -> Result<Arc<str>, LoadError> { ... }
}Expand description
Abstract file system interface for file loading.
This trait allows the loader to work with different file system backends:
DiskFileSystem: Reads from the actual filesystem (default)VirtualFileSystem: Reads from an in-memory file map (for WASM)
Required Methods§
Sourcefn is_encrypted(&self, path: &Path) -> bool
fn is_encrypted(&self, path: &Path) -> bool
Check if a path is a GPG-encrypted file.
For virtual filesystems, this always returns false since encrypted files should be decrypted before being added.
Provided Methods§
Sourcefn supports_parallel_read(&self) -> bool
fn supports_parallel_read(&self) -> bool
Whether this filesystem supports parallel file reads.
Disk filesystems return true — multiple files can be read
concurrently from different threads. Virtual filesystems return
false since they may use shared mutable state.
Sourcefn glob(&self, pattern: &str) -> Result<Vec<PathBuf>, String>
fn glob(&self, pattern: &str) -> Result<Vec<PathBuf>, String>
Expand a glob pattern and return matching paths.
§Errors
Returns an error string if the pattern is invalid.
Sourcefn decrypt(&self, path: &Path) -> Result<Arc<str>, LoadError>
fn decrypt(&self, path: &Path) -> Result<Arc<str>, LoadError>
Decrypt an encrypted file at path, returning its plaintext.
The default implementation shells out to gpg --batch --decrypt — the
native path, which uses the user’s keyring and gpg-agent. Sandboxed
filesystems (the WASI component) override this to delegate to a host
capability, since a WASI guest can neither spawn gpg nor reach the
keyring (#1667). Only called when is_encrypted
returned true.
§Errors
Returns LoadError::Decryption if decryption fails.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".