Skip to main content

Extension

Trait Extension 

Source
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§

Source

fn name(&self) -> &str

For diagnostics.

Provided Methods§

Source

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).

Source

fn loaders(&self) -> Vec<(BoxResolver, BoxLoader)>

Resolver/loader pairs consulted after the native registry and before the file loader.

Source

fn require_hook(&self) -> Option<Arc<dyn RequireHook>>

Something that answers require() ahead of the registry.

Source

fn install(&self, _ctx: &Ctx<'_>) -> Result<()>

Install globals, once per realm. The synchronous form; most extensions need nothing else.

§Errors

Propagates the installs.

Source

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".

Implementors§

Source§

impl Extension for FetchExtension

Source§

impl<F> Extension for FnExtension<F>
where F: for<'js> Fn(&Ctx<'js>) -> Result<()> + Send + Sync,