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

source

pub fn load<T: Loader>(&self, loader: T) -> Result<T::Instance, T::Error>

Load an Instance using the given loader.

source

pub 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

Through generic magic and the awe-inspiring power of traits, we bring you…

§“Func”

A Func allows you to call functions exported from wasm with near zero overhead.

§Usage:
let func: Func<(i32, i32)> = instance.func("foo")?;

func.call(42, 43);
source

pub fn resolve_func(&self, name: &str) -> ResolveResult<usize>

Resolve a function by name.

source

pub fn dyn_func(&self, name: &str) -> ResolveResult<DynFunc<'_>>

👎Deprecated since 0.17.0: Please use instance.exports.get(name) instead

This returns the representation of a function that can be called safely.

§Usage:
instance
    .dyn_func("foo")?
    .call(&[])?;
source

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)])?;
// ...
source

pub fn context(&self) -> &Ctx

Returns an immutable reference to the Ctx used by this Instance.

source

pub fn context_mut(&mut self) -> &mut Ctx

Returns a mutable reference to the Ctx used by this Instance.

source

pub fn exports(&self) -> ExportIter<'_>

Returns an iterator over all of the items exported from this instance.

source

pub fn module(&self) -> Module

The module used to instantiate this Instance.

source

pub fn get_internal(&self, field: &InternalField) -> u64

Get the value of an internal field

source

pub fn set_internal(&mut self, field: &InternalField, value: u64)

Set the value of an internal field.

Trait Implementations§

source§

impl LikeNamespace for Instance

source§

fn get_export(&self, name: &str) -> Option<Export>

Gets an export by name.
source§

fn get_exports(&self) -> Vec<(String, Export)>

Gets all exports in the namespace.
source§

fn maybe_insert(&mut self, _name: &str, _export: Export) -> Option<()>

Maybe insert an Export by name into the namespace.

Auto Trait Implementations§

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> Same for T

§

type Output = T

Should always be Self
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.