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§
Sourcefn read_file(&self, path: &str) -> Option<String>
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.
Provided Methods§
Sourcefn real_path(&self, path: &str) -> Option<String>
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.
Sourcefn native_paths(&self) -> bool
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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".