Skip to main content

SourceFs

Trait SourceFs 

Source
pub trait SourceFs: Send + Sync {
    // Required methods
    fn read_file(&self, path: &str) -> Option<String>;
    fn read_dir(&self, path: &str) -> Option<Vec<DirEntry>>;
    fn join(&self, parts: &[&str]) -> String;
    fn dir(&self, path: &str) -> String;
    fn canon(&self, path: &str) -> String;

    // Provided methods
    fn real_path(&self, path: &str) -> Option<String> { ... }
    fn native_paths(&self) -> bool { ... }
}
Expand description

A read-only view of a filesystem.

Every path a resolver touches goes through one of these, so a caller decides what a document can reach. OsFs reads the real filesystem with absolute paths; MapFs reads an in-memory map with relative, slash-separated paths, the Rust counterpart of Go’s testing/fstest.MapFS and of the memfs the TypeScript tests inject.

Implementations must be Send + Sync: a Tabnas instance parses through &self and may be shared between threads.

Required Methods§

Source

fn read_file(&self, path: &str) -> Option<String>

Read the file at a canonical path. None means it is not there, or cannot be read, which resolution treats the same way.

Source

fn read_dir(&self, path: &str) -> Option<Vec<DirEntry>>

List a directory. None means it is not there or is unreadable.

Source

fn join(&self, parts: &[&str]) -> String

Join path elements in this filesystem’s convention.

Source

fn dir(&self, path: &str) -> String

The parent directory of path.

Source

fn canon(&self, path: &str) -> String

The canonical lookup form of a possibly relative path.

Provided Methods§

Source

fn real_path(&self, path: &str) -> Option<String>

The path path names once every link on the way to it has been followed, which is what a sandbox root has to be compared against: a purely lexical comparison answers for the path as written, and a later read follows the links.

None means the path cannot be reduced to a real one and must therefore be refused rather than guessed at: a dangling or looping symbolic link is the case, and its target could come into existence before the read.

The default is the lexical SourceFs::canon, which is exact for a filesystem that has no links at all, such as MapFs. OsFs overrides it, because the real one does.

Source

fn native_paths(&self) -> bool

Whether this filesystem addresses files by NATIVE absolute paths, as OsFs does, rather than by relative, slash-separated ones.

It decides only how a sandbox root is compared against a candidate, and the default is the conservative answer: an injected filesystem keys on slashes, so / is the separator and a Windows drive letter is not in play.

Trait Implementations§

Source§

impl Debug for dyn SourceFs

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§