pub trait ModuleLoader {
// Required method
fn load(
&self,
specifier: &str,
attributes: &[(String, String)],
referrer: &str,
) -> Result<LoadedModule, String>;
// Provided method
fn resolve(&self, specifier: &str, referrer: &str) -> Option<String> { ... }
}Expand description
How the host turns a specifier into bytes.
The engine cannot do this itself: resolving ./x.js needs to know that the importer
was a file, and where. A browser-shaped host would answer differently, so the host
supplies this and the engine decides what to do with the bytes.
Required Methods§
Provided Methods§
Sourcefn resolve(&self, specifier: &str, referrer: &str) -> Option<String>
fn resolve(&self, specifier: &str, referrer: &str) -> Option<String>
The name specifier resolves to from referrer, without reading anything.
A precompiled module is registered under the name a loader would give it, so the
engine has to know that name before it can decide whether the module is already in
memory. Without this the only way to ask is ModuleLoader::load, which reads the
file — and a product that carries its dependencies has no files to read.
None means “this loader can only answer by loading”, which is the behaviour a
loader that resolves against something other than text (an in-memory map, a
network) legitimately has. Precompiled modules are then matched after the load, by
the name the load reported.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".