Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem: Send + Sync {
    // Required methods
    fn read_to_string(&self, path: &Path) -> Result<String, AnalysisError>;
    fn write(&self, path: &Path, content: &str) -> Result<(), AnalysisError>;
    fn exists(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
    fn is_dir(&self, path: &Path) -> bool;
    fn read_bytes(&self, path: &Path) -> Result<Vec<u8>, AnalysisError>;
}
Expand description

File system operations trait.

This trait abstracts over file system operations, enabling:

  • Unit testing with mock file systems
  • Virtual file system implementations
  • Read-only or sandboxed file access

§Implementation Notes

Implementations should be thread-safe (Send + Sync) to support parallel analysis across multiple files.

Required Methods§

Source

fn read_to_string(&self, path: &Path) -> Result<String, AnalysisError>

Read a file’s contents as a UTF-8 string.

§Errors

Returns AnalysisError::IoError if:

  • The file doesn’t exist
  • Permission is denied
  • The file isn’t valid UTF-8
Source

fn write(&self, path: &Path, content: &str) -> Result<(), AnalysisError>

Write content to a file, creating it if it doesn’t exist.

§Errors

Returns AnalysisError::IoError if:

  • Permission is denied
  • Parent directory doesn’t exist
  • Disk is full
Source

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

Check if a path exists (file or directory).

Source

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

Check if a path is a file.

Source

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

Check if a path is a directory.

Source

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

Read a file’s contents as raw bytes.

§Errors

Returns AnalysisError::IoError if:

  • The file doesn’t exist
  • Permission is denied

Implementors§