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

Implementors§