pub struct Instance {
pub module: Arc<ModuleInner>,
pub exports: Exports,
/* private fields */
}Expand description
An instantiated WebAssembly module.
An Instance represents a WebAssembly module that
has been instantiated with an ImportObject and is
ready to be called.
Fields§
§module: Arc<ModuleInner>Reference to the module used to instantiate this instance.
exports: ExportsThe exports of this instance.
Implementations§
Source§impl Instance
impl Instance
Sourcepub fn load<T>(
&self,
loader: T,
) -> Result<<T as Loader>::Instance, <T as Loader>::Error>where
T: Loader,
pub fn load<T>(
&self,
loader: T,
) -> Result<<T as Loader>::Instance, <T as Loader>::Error>where
T: Loader,
Load an Instance using the given loader.
Sourcepub fn func<Args, Rets>(
&self,
name: &str,
) -> Result<Func<'_, Args, Rets>, ResolveError>where
Args: WasmTypeList,
Rets: WasmTypeList,
👎Deprecated since 0.17.0: Please use instance.exports.get(name) instead
pub fn func<Args, Rets>(
&self,
name: &str,
) -> Result<Func<'_, Args, Rets>, ResolveError>where
Args: WasmTypeList,
Rets: WasmTypeList,
instance.exports.get(name) insteadSourcepub fn resolve_func(&self, name: &str) -> Result<usize, ResolveError>
pub fn resolve_func(&self, name: &str) -> Result<usize, ResolveError>
Resolve a function by name.
Sourcepub fn dyn_func(&self, name: &str) -> Result<DynFunc<'_>, ResolveError>
👎Deprecated since 0.17.0: Please use instance.exports.get(name) instead
pub fn dyn_func(&self, name: &str) -> Result<DynFunc<'_>, ResolveError>
instance.exports.get(name) insteadThis returns the representation of a function that can be called safely.
§Usage:
instance
.dyn_func("foo")?
.call(&[])?;Sourcepub fn call(
&self,
name: &str,
params: &[Value],
) -> Result<Vec<Value>, CallError>
pub fn call( &self, name: &str, params: &[Value], ) -> Result<Vec<Value>, CallError>
Call an exported WebAssembly function given the export name.
Pass arguments by wrapping each one in the Value enum.
The returned values are also each wrapped in a Value.
§Note:
This returns CallResult<Vec<Value>> in order to support
the future multi-value returns WebAssembly feature.
Consider using the more explicit Exports::get with [DynFunc::call`]
instead. For example:
// ...
let foo: DynFunc = instance.exports.get("foo")?;
let results = foo.call(&[Value::I32(42)])?;
// ...§Usage:
// ...
let results = instance.call("foo", &[Value::I32(42)])?;
// ...Sourcepub fn context_mut(&mut self) -> &mut Ctx
pub fn context_mut(&mut self) -> &mut Ctx
Returns a mutable reference to the
Ctx used by this Instance.
Sourcepub fn exports(&self) -> ExportIter<'_>
pub fn exports(&self) -> ExportIter<'_>
Returns an iterator over all of the items exported from this instance.
Sourcepub fn get_internal(&self, field: &InternalField) -> u64
pub fn get_internal(&self, field: &InternalField) -> u64
Get the value of an internal field
Sourcepub fn set_internal(&mut self, field: &InternalField, value: u64)
pub fn set_internal(&mut self, field: &InternalField, value: u64)
Set the value of an internal field.