Trait Runtime

Source
pub trait Runtime:
    Debug
    + Send
    + Sync {
    // Required methods
    fn identifier(&self) -> &'static str;
    fn prepare_module(&self, bytes: &[u8]) -> Result<ModuleCache>;
    fn init(
        &self,
        name: &str,
        imports: Vec<(String, Func)>,
        envs: Vec<(String, String)>,
        module: Module,
    ) -> Result<Box<dyn Instance>>;

    // Provided methods
    fn clone_cache(&self, _cache: &ModuleCache) -> Option<ModuleCache> { ... }
    unsafe fn load_cache(&self, _path: &Path) -> Option<ModuleCache> { ... }
    fn store_cache(&self, _path: &Path, _cache: &ModuleCache) -> Result<()> { ... }
}
Expand description

Plugin runtime abstract

Required Methods§

Source

fn identifier(&self) -> &'static str

An identifier used to identify the runtime implement, which should include the runtime name and version.

Source

fn prepare_module(&self, bytes: &[u8]) -> Result<ModuleCache>

Preprocess raw bytes into module cache

Note that it is not mandatory to implement AOT. It can just be loaded as an object.

Source

fn init( &self, name: &str, imports: Vec<(String, Func)>, envs: Vec<(String, String)>, module: Module, ) -> Result<Box<dyn Instance>>

Initialize the plugin instance

  • name and envs parameters are module name and environment variable pairs. They can be ignored for non-wasi modules.
  • imports parameters should be provided as env module.
  • The runtime should call the __get_transform_plugin_core_pkg_diag function once after instantiation to check that initialization was completed correctly.

Provided Methods§

Source

fn clone_cache(&self, _cache: &ModuleCache) -> Option<ModuleCache>

Clone module cache

If the runtime does not allow clone, then it can return None.

Source

unsafe fn load_cache(&self, _path: &Path) -> Option<ModuleCache>

Load a module from file

§Safety

This function is marked as unsafe, allow to load trusted module cache without verification.

Source

fn store_cache(&self, _path: &Path, _cache: &ModuleCache) -> Result<()>

Store a module to file

Implementors§