Skip to main content

Loader

Trait Loader 

Source
pub trait Loader {
    // Required method
    fn load(&self, path: &Path) -> Result<LoadedFile, LoadError>;
}
Expand description

A pluggable source-text loader.

Implementations decide where bytes come from (filesystem, in-memory map, virtual filesystem, content-addressed store, …). lex-core never references std::fs directly through this trait; that keeps the resolver pure and usable in WASM, sandboxes, and unit tests.

Required Methods§

Source

fn load(&self, path: &Path) -> Result<LoadedFile, LoadError>

Load the source text for path and return both the contents and a canonical identity for the loaded resource. The path is what the resolver decided on after applying the rules in §4 of the proposal.

LoadedFile::canonical_path is the loader’s authoritative identity for the resource. For FsLoader this is the filesystem-canonical path (symlinks resolved, case-folded if the underlying FS is case-insensitive); for [MemoryLoader] it’s the lookup key (since memory loaders have no symlinks). The resolver uses this for cycle detection and for stamping Range.origin_path on the loaded tree.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§