Struct wasmer_runtime_core_x::Instance
source · 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: Exports
The exports of this instance.
Implementations§
source§impl Instance
impl Instance
sourcepub fn load<T: Loader>(&self, loader: T) -> Result<T::Instance, T::Error>
pub fn load<T: Loader>(&self, loader: T) -> Result<T::Instance, T::Error>
Load an Instance
using the given loader.
sourcepub fn func<Args, Rets>(
&self,
name: &str
) -> ResolveResult<Func<'_, Args, Rets, Wasm>>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
) -> ResolveResult<Func<'_, Args, Rets, Wasm>>where
Args: WasmTypeList,
Rets: WasmTypeList,
instance.exports.get(name)
insteadsourcepub fn resolve_func(&self, name: &str) -> ResolveResult<usize>
pub fn resolve_func(&self, name: &str) -> ResolveResult<usize>
Resolve a function by name.
sourcepub fn dyn_func(&self, name: &str) -> ResolveResult<DynFunc<'_>>
👎Deprecated since 0.17.0: Please use instance.exports.get(name)
instead
pub fn dyn_func(&self, name: &str) -> ResolveResult<DynFunc<'_>>
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]) -> CallResult<Vec<Value>>
pub fn call(&self, name: &str, params: &[Value]) -> CallResult<Vec<Value>>
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.