pub trait SourceProvider {
// Required methods
fn read(&self, path: &Path) -> Result<String>;
fn is_file(&self, path: &Path) -> bool;
fn canonicalize(&self, path: &Path) -> Result<PathBuf>;
}Expand description
Where the Legacy loader gets source text from.
Three operations, which is the entire filesystem surface of the
@require:/@import: path: read a file, probe a resolution candidate,
and turn a path into the identity its dependency-graph node is keyed by.
The seam exists because wasm32-unknown-unknown has no filesystem at all,
and a SATySFi document that cannot @require: anything is barely a
document — the browser playground serves the bundled 0.0.6 corpus straight
out of the binary through this trait. It is also the honest way to write a
loader test that needs a dependency graph but not a temp directory.
LoadOptions::sources is None by default, which means FsSources —
the real filesystem, byte-for-byte the behaviour that predates this trait.
Required Methods§
Sourcefn read(&self, path: &Path) -> Result<String>
fn read(&self, path: &Path) -> Result<String>
The file’s text. Err is surfaced as LoadError::Io.
Sourcefn is_file(&self, path: &Path) -> bool
fn is_file(&self, path: &Path) -> bool
Whether path names a readable file. Drives candidate selection in
@require:/@import: resolution, so a false here is an ordinary
“try the next candidate”, not an error.
Sourcefn canonicalize(&self, path: &Path) -> Result<PathBuf>
fn canonicalize(&self, path: &Path) -> Result<PathBuf>
path’s canonical form — the key two headers naming the same file
must agree on, or it would be loaded (and its bindings emitted) twice.
A provider whose paths are already unique and absolute by construction
may return path unchanged; the loader only requires that the same
file always maps to the same key. Note that the per-file version
detector reads the RESULT, so a provider serving the frozen 0.0.6
corpus must keep the dist/packages components in it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".