Struct wasmedge_sys::ImportModule

source ·
pub struct ImportModule<T: ?Sized> { /* private fields */ }
Expand description

An ImportModule represents a host module with a name. A host module consists of one or more host function, table, memory, and global instances, which are defined outside wasm modules and fed into wasm modules as imports.

Implementations§

source§

impl<T: Sized> ImportModule<T>

source

pub fn create(name: impl AsRef<str>, data: Box<T>) -> WasmEdgeResult<Self>

Creates a module instance which is used to import host functions, tables, memories, and globals into a wasm module.

§Argument
  • name - The name of the import module instance.

  • data - The host context data used in this function.

§Error

If fail to create the import module instance, then an error is returned.

source

pub unsafe fn as_raw(&self) -> *mut WasmEdge_ModuleInstanceContext

§Safety

Provides a raw pointer to the inner module instance context. The lifetime of the returned pointer must not exceed that of the object itself.

source

pub unsafe fn from_raw(ctx: *mut WasmEdge_ModuleInstanceContext) -> Self

§Safety

This function will take over the lifetime management of ctx, so do not call ffi::WasmEdge_ModuleInstanceDelete on ctx after this.

source

pub fn get_host_data(&self) -> &T

source

pub fn get_host_data_mut(&mut self) -> &mut T

source§

impl<T: Sized> ImportModule<T>

source

pub fn add_func(&mut self, name: impl AsRef<str>, func: Function)

source

pub fn add_table(&mut self, name: impl AsRef<str>, table: Table)

source

pub fn add_memory(&mut self, name: impl AsRef<str>, memory: Memory)

source

pub fn add_global(&mut self, name: impl AsRef<str>, global: Global)

Trait Implementations§

source§

impl<T: Sized> AsInstance for ImportModule<T>

source§

unsafe fn as_ptr(&self) -> *const WasmEdge_ModuleInstanceContext

Safety Read more
source§

fn name(&self) -> Option<String>

Returns the name of this exported module instance. Read more
source§

fn get_table( &self, name: impl AsRef<str> ) -> WasmEdgeResult<InnerRef<Table, &Self>>
where Self: Sized,

Returns the exported table instance by name. Read more
source§

fn get_memory_ref( &self, name: impl AsRef<str> ) -> WasmEdgeResult<InnerRef<Memory, &Self>>
where Self: Sized,

Returns the exported memory instance by name. Read more
source§

fn get_memory_mut( &mut self, name: impl AsRef<str> ) -> WasmEdgeResult<InnerRef<Memory, &mut Self>>
where Self: Sized,

source§

fn get_global( &self, name: impl AsRef<str> ) -> WasmEdgeResult<InnerRef<Global, &Self>>
where Self: Sized,

Returns the exported global instance by name. Read more
source§

fn get_global_mut( &mut self, name: impl AsRef<str> ) -> WasmEdgeResult<InnerRef<Global, &mut Self>>
where Self: Sized,

source§

fn func_len(&self) -> u32

Returns the length of the exported function instances in this module instance.
source§

fn func_names(&self) -> Option<Vec<String>>

Returns the names of the exported function instances in this module instance.
source§

fn get_func(&self, name: &str) -> WasmEdgeResult<FuncRef<&Instance>>

Returns the exported function instance by name. Read more
source§

fn get_func_mut(&mut self, name: &str) -> WasmEdgeResult<FuncRef<&mut Instance>>

Returns the exported function instance by name. Read more
source§

fn table_len(&self) -> u32

Returns the length of the exported table instances in this module instance.
source§

fn table_names(&self) -> Option<Vec<String>>

Returns the names of the exported table instances in this module instance.
source§

fn mem_len(&self) -> u32

Returns the length of the exported memory instances in this module instance.
source§

fn mem_names(&self) -> Option<Vec<String>>

Returns the names of all exported memory instances in this module instance.
source§

fn global_len(&self) -> u32

Returns the length of the exported global instances in this module instance.
source§

fn global_names(&self) -> Option<Vec<String>>

Returns the names of the exported global instances in this module instance.
source§

impl<T: Send> AsMut<ImportModule<T>> for AsyncImportObject<T>

Available on crate feature async and Linux only.
source§

fn as_mut(&mut self) -> &mut ImportModule<T>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T: Send> AsRef<ImportModule<T>> for AsyncImportObject<T>

Available on crate feature async and Linux only.
source§

fn as_ref(&self) -> &ImportModule<T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Debug + ?Sized> Debug for ImportModule<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: ?Sized> Drop for ImportModule<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ImportModule<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for ImportModule<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for ImportModule<T>
where T: Send + ?Sized,

§

impl<T> Sync for ImportModule<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for ImportModule<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for ImportModule<T>
where T: UnwindSafe + ?Sized,

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

§

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

§

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.