Skip to main content

ModuleLoader

Trait ModuleLoader 

Source
pub trait ModuleLoader {
    // Required methods
    fn normalize_path(
        &self,
        q_ctx: &QuickJsRealmAdapter,
        ref_path: &str,
        path: &str,
    ) -> Option<String>;
    fn load_module(
        &self,
        q_ctx: &QuickJsRealmAdapter,
        absolute_path: &str,
    ) -> Result<*mut JSModuleDef, JsError>;
    fn has_module(
        &self,
        q_ctx: &QuickJsRealmAdapter,
        absolute_path: &str,
    ) -> bool;
    unsafe fn init_module(
        &self,
        q_ctx: &QuickJsRealmAdapter,
        module: *mut JSModuleDef,
    ) -> Result<(), JsError>;
}
Expand description

this is the internal abstract loader which is used to actually load the modules

Required Methods§

Source

fn normalize_path( &self, q_ctx: &QuickJsRealmAdapter, ref_path: &str, path: &str, ) -> Option<String>

the normalize methods is used to translate a possible relative path to an absolute path of a module it doubles as a method to see IF a module can actually be loaded by a module loader (return None if the module can not be found)

Source

fn load_module( &self, q_ctx: &QuickJsRealmAdapter, absolute_path: &str, ) -> Result<*mut JSModuleDef, JsError>

load the Module

Source

fn has_module(&self, q_ctx: &QuickJsRealmAdapter, absolute_path: &str) -> bool

has module is used to check if a loader can provide a certain module, this is currently used to check which loader should init a native module

Source

unsafe fn init_module( &self, q_ctx: &QuickJsRealmAdapter, module: *mut JSModuleDef, ) -> Result<(), JsError>

init a module, currently used to init native modules

§Safety

be safe with the moduledef ptr

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§