Struct Module

Source
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>

Source

pub fn parse<TData: Into<Box<[u8]>>>( environment: &Environment, bytes: TData, ) -> Result<ParsedModule>

Parses a wasm module from raw bytes.

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

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
Source

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
Source

pub fn function<Args, Ret>( &self, function_index: usize, ) -> Result<Function<'rt, Args, Ret>>
where Args: WasmArgs, Ret: WasmType,

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
Source

pub fn name(&self) -> &str

The name of this module.

Links wasi to this module.

Auto Trait Implementations§

§

impl<'rt> Freeze for Module<'rt>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.