pub struct Module<'rt> { /* private fields */ }
Expand description
A loaded module belonging to a specific runtime. Allows for linking and looking up functions.
Implementations
sourceimpl<'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<()> where
Args: WasmArgs,
Ret: WasmType,
pub fn link_function<Args, Ret>(
&mut self,
module_name: &str,
function_name: &str,
f: RawCall
) -> Result<()> where
Args: WasmArgs,
Ret: WasmType,
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<()> where
Args: WasmArgs,
Ret: WasmType,
F: for<'cc> FnMut(CallContext<'cc>, Args) -> Result<Ret, Trap> + 'static,
pub fn link_closure<Args, Ret, F>(
&mut self,
module_name: &str,
function_name: &str,
closure: F
) -> Result<()> where
Args: WasmArgs,
Ret: WasmType,
F: for<'cc> FnMut(CallContext<'cc>, Args) -> Result<Ret, Trap> + 'static,
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>> where
Args: WasmArgs,
Ret: WasmType,
pub fn find_function<Args, Ret>(
&self,
function_name: &str
) -> Result<Function<'rt, Args, Ret>> where
Args: WasmArgs,
Ret: WasmType,
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
Auto Trait Implementations
impl<'rt> !RefUnwindSafe for Module<'rt>
impl<'rt> !Send for Module<'rt>
impl<'rt> !Sync for Module<'rt>
impl<'rt> Unpin for Module<'rt>
impl<'rt> !UnwindSafe for Module<'rt>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more