Skip to main content

FileSystem

Trait FileSystem 

Source
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> { ... }
}
Expand description

Abstract file system interface for file loading.

This trait allows the loader to work with different file system backends:

Required Methods§

Source

fn read(&self, path: &Path) -> Result<Arc<str>, LoadError>

Read file content at the given path.

§Errors

Returns LoadError::Io if the file cannot be read.

Source

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

Check if a file exists at the given path.

Source

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.

Source

fn normalize(&self, path: &Path) -> PathBuf

Normalize a path for this filesystem.

For disk filesystems, this makes paths absolute. For virtual filesystems, this just cleans up the path.

Provided Methods§

Source

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.

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§