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§
Sourcefn identifier(&self) -> &'static str
fn identifier(&self) -> &'static str
An identifier used to identify the runtime implement, which should include the runtime name and version.
Sourcefn prepare_module(&self, bytes: &[u8]) -> Result<ModuleCache>
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.
Sourcefn init(
&self,
name: &str,
imports: Vec<(String, Func)>,
envs: Vec<(String, String)>,
module: Module,
) -> Result<Box<dyn Instance>>
fn init( &self, name: &str, imports: Vec<(String, Func)>, envs: Vec<(String, String)>, module: Module, ) -> Result<Box<dyn Instance>>
Initialize the plugin instance
name
andenvs
parameters are module name and environment variable pairs. They can be ignored for non-wasi modules.imports
parameters should be provided asenv
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§
Sourcefn clone_cache(&self, _cache: &ModuleCache) -> Option<ModuleCache>
fn clone_cache(&self, _cache: &ModuleCache) -> Option<ModuleCache>
Clone module cache
If the runtime does not allow clone, then it can return None
.
Sourceunsafe fn load_cache(&self, _path: &Path) -> Option<ModuleCache>
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.
Sourcefn store_cache(&self, _path: &Path, _cache: &ModuleCache) -> Result<()>
fn store_cache(&self, _path: &Path, _cache: &ModuleCache) -> Result<()>
Store a module to file