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§
Sourcefn read_to_string(&self, path: &Path) -> Result<String, AnalysisError>
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
Sourcefn write(&self, path: &Path, content: &str) -> Result<(), AnalysisError>
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
Sourcefn read_bytes(&self, path: &Path) -> Result<Vec<u8>, AnalysisError>
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