pub struct Module<'rt> { /* private fields */ }
Expand description
A loaded module belonging to a specific runtime. Allows for linking and looking up functions.
Implementations§
Source§impl<'rt> Module<'rt>
impl<'rt> Module<'rt>
Sourcepub fn parse<TData: Into<Box<[u8]>>>(
environment: &Environment,
bytes: TData,
) -> Result<ParsedModule>
pub fn parse<TData: Into<Box<[u8]>>>( environment: &Environment, bytes: TData, ) -> Result<ParsedModule>
Parses a wasm module from raw bytes.
Sourcepub fn link_function<Args, Ret>(
&mut self,
module_name: &str,
function_name: &str,
f: RawCall,
) -> Result<()>
pub fn link_function<Args, Ret>( &mut self, module_name: &str, function_name: &str, f: RawCall, ) -> Result<()>
Links the given function to the corresponding module and function name.
This allows linking a more verbose function, as it gets access to the unsafe
runtime parts. For easier use the [make_func_wrapper
] should be used to create
the unsafe facade for your function that then can be passed to this.
For a simple API see link_closure
which takes a closure instead.
§Errors
This function will return an error in the following situations:
- a memory allocation failed
- no function by the given name in the given module could be found
- the function has been found but the signature did not match
Sourcepub fn link_closure<Args, Ret, F>(
&mut self,
module_name: &str,
function_name: &str,
closure: F,
) -> Result<()>
pub fn link_closure<Args, Ret, F>( &mut self, module_name: &str, function_name: &str, closure: F, ) -> Result<()>
Links the given closure to the corresponding module and function name. This boxes the closure and therefor requires a heap allocation.
§Errors
This function will return an error in the following situations:
- a memory allocation failed
- no function by the given name in the given module could be found
- the function has been found but the signature did not match
Sourcepub fn find_function<Args, Ret>(
&self,
function_name: &str,
) -> Result<Function<'rt, Args, Ret>>
pub fn find_function<Args, Ret>( &self, function_name: &str, ) -> Result<Function<'rt, Args, Ret>>
Looks up a function by the given name in this module.
§Errors
This function will return an error in the following situations:
- a memory allocation failed
- no function by the given name in the given module could be found
- the function has been found but the signature did not match
Sourcepub fn function<Args, Ret>(
&self,
function_index: usize,
) -> Result<Function<'rt, Args, Ret>>
pub fn function<Args, Ret>( &self, function_index: usize, ) -> Result<Function<'rt, Args, Ret>>
Looks up a function by its index in this module.
§Errors
This function will return an error in the following situations:
- a memory allocation failed
- the index is out of bounds
- the function has been found but the signature did not match