Skip to main content

SourceResolver

Trait SourceResolver 

Source
pub trait SourceResolver {
    // Required methods
    fn resolve(
        &mut self,
        importer: Option<&SourceId>,
        spec: &str,
    ) -> Result<SourceId, String>;
    fn fetch(&mut self, id: &SourceId) -> Result<ImportSource, String>;
}
Expand description

Host-supplied import IO: turns literal specifiers into canonical ids and canonical ids into source text.

This is the only place bytes enter the loader — the kit core stays io-free, mirroring Jsonnet’s import_callback / Starlark’s embedder-owned load resolution. resolve receives the importing source (or None for the root document) so relative-path schemes can canonicalise against the importer, and is split from fetch so the loader can dedupe on the canonical id before paying for IO.

Required Methods§

Source

fn resolve( &mut self, importer: Option<&SourceId>, spec: &str, ) -> Result<SourceId, String>

Canonicalises spec (as written at the import site inside importer) into a SourceId.

Errors are reported as import_codes::RESOLVE_FAILED.

Source

fn fetch(&mut self, id: &SourceId) -> Result<ImportSource, String>

Produces the source document for a resolved id.

Called at most once per id per load_json_str call; errors are reported as import_codes::FETCH_FAILED and cached, so a broken source fails every site that imports it without being re-fetched.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§