pub trait Extension: Send + Sync {
// Required method
fn name(&self) -> &str;
// Provided methods
fn modules(&self, _registry: &mut ModuleRegistry) -> Result<(), String> { ... }
fn loaders(&self) -> Vec<(BoxResolver, BoxLoader)> { ... }
fn require_hook(&self) -> Option<Arc<dyn RequireHook>> { ... }
fn install(&self, _ctx: &Ctx<'_>) -> Result<()> { ... }
fn install_async<'js>(
&self,
ctx: Ctx<'js>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'js>> { ... }
}Expand description
A unit of host surface.
Required Methods§
Provided Methods§
Sourcefn modules(&self, _registry: &mut ModuleRegistry) -> Result<(), String>
fn modules(&self, _registry: &mut ModuleRegistry) -> Result<(), String>
Native modules this extension serves. Registered before the realm exists, so a bundler and the loader see one table.
§Errors
A specifier already served (see ModuleRegistry::register).
Sourcefn loaders(&self) -> Vec<(BoxResolver, BoxLoader)>
fn loaders(&self) -> Vec<(BoxResolver, BoxLoader)>
Resolver/loader pairs consulted after the native registry and before the file loader.
Sourcefn require_hook(&self) -> Option<Arc<dyn RequireHook>>
fn require_hook(&self) -> Option<Arc<dyn RequireHook>>
Something that answers require() ahead of the registry.
Sourcefn install(&self, _ctx: &Ctx<'_>) -> Result<()>
fn install(&self, _ctx: &Ctx<'_>) -> Result<()>
Install globals, once per realm. The synchronous form; most extensions need nothing else.
§Errors
Propagates the installs.
Sourcefn install_async<'js>(
&self,
ctx: Ctx<'js>,
) -> Pin<Box<dyn Future<Output = Result<()>> + 'js>>
fn install_async<'js>( &self, ctx: Ctx<'js>, ) -> Pin<Box<dyn Future<Output = Result<()>> + 'js>>
Self::install for an extension whose install awaits (one that
evaluates a module, say). Runs on the VM loop; the default calls
the synchronous form.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".