Skip to main content

FileSystem

Trait FileSystem 

Source
pub trait FileSystem:
    Send
    + Sync
    + Debug {
    // Required methods
    fn exists(&self, path: &Path) -> bool;
    fn is_file(&self, path: &Path) -> bool;
    fn is_dir(&self, path: &Path) -> bool;
    fn is_symlink(&self, path: &Path) -> bool;
    fn metadata(&self, path: &Path) -> Result<FileMetadata>;
    fn symlink_metadata(&self, path: &Path) -> Result<FileMetadata>;
    fn read_to_string(&self, path: &Path) -> LintResult<String>;
    fn write(&self, path: &Path, content: &str) -> LintResult<()>;
    fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
    fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>;
}
Expand description

Trait for abstracting file system operations.

This trait must be Send + Sync to support rayon parallel validation. It also requires Debug for use in config structs that derive Debug.

Required Methods§

Source

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

Check if a path exists

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

Check if a path is a symlink

Source

fn metadata(&self, path: &Path) -> Result<FileMetadata>

Get metadata for a path (follows symlinks)

Get metadata for a path without following symlinks

Source

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

Read file contents to string (with security checks)

Source

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

Write content to file (with security checks)

Source

fn canonicalize(&self, path: &Path) -> Result<PathBuf>

Canonicalize a path

Source

fn read_dir(&self, path: &Path) -> Result<Vec<DirEntry>>

Read directory contents

Implementors§