pub struct Imports { /* private fields */ }
Expand description
Imports for a module instance
This is used to link a module instance to its imports
§Example
use tinywasm::{Imports, Extern};
use tinywasm::types::{ValType, TableType, MemoryType, WasmValue};
let mut imports = Imports::new();
// function args can be either a single
// value that implements `TryFrom<WasmValue>` or a tuple of them
let print_i32 = Extern::typed_func(|_ctx: tinywasm::FuncContext<'_>, arg: i32| {
log::debug!("print_i32: {}", arg);
Ok(())
});
let table_type = TableType::new(ValType::RefFunc, 10, Some(20));
let table_init = WasmValue::default_for(ValType::RefFunc);
imports
.define("my_module", "print_i32", print_i32)?
.define("my_module", "table", Extern::table(table_type, table_init))?
.define("my_module", "memory", Extern::memory(MemoryType::new_32(1, Some(2))))?
.define("my_module", "global_i32", Extern::global(WasmValue::I32(666), false))?
.link_module("my_other_module", 0)?;
Note that module instance addresses for Imports::link_module
can be obtained from crate::ModuleInstance::id
.
Now, the imports object can be passed to crate::ModuleInstance::instantiate
.
Implementations§
Source§impl Imports
impl Imports
Sourcepub fn link_module(
&mut self,
name: &str,
addr: ModuleInstanceAddr,
) -> Result<&mut Self>
pub fn link_module( &mut self, name: &str, addr: ModuleInstanceAddr, ) -> Result<&mut Self>
Link a module
This will automatically link all imported values on instantiation
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Imports
impl !RefUnwindSafe for Imports
impl !Send for Imports
impl !Sync for Imports
impl Unpin for Imports
impl !UnwindSafe for Imports
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.