[][src]Struct wasmer_runtime::Instance

pub struct Instance {
    pub exports: Exports,
    // some fields omitted
}

An instantiated WebAssembly module.

An Instance represents a WebAssembly module that has been instantiated with an ImportObject and is ready to be called.

Fields

exports: Exports

The exports of this instance.

Implementations

impl Instance[src]

pub fn func<Args, Rets>(
    &self,
    name: &str
) -> Result<Func<Args, Rets>, ExportError> where
    Args: WasmTypeList + Clone,
    Rets: WasmTypeList + Clone
[src]

👎 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);

pub fn dyn_func(&self, name: &str) -> Result<DynamicFunc, ExportError>[src]

👎 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(&[])?;

pub fn resolve_func(&self, name: &str) -> Result<usize, ()>[src]

Resolve an exported function by name.

pub fn call(
    &self,
    name: &str,
    params: &[Value<Function>]
) -> Result<Vec<Value<Function>>, Box<dyn Error + 'static>>
[src]

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 Result<Vec<Value>, _> in order to support the future multi-value returns WebAssembly feature.

Usage

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

Another example with Instance::call directly:

// ...
let results = instance.call("foo", &[Value::I32(42)])?;
// ...

pub fn module(&self) -> Module[src]

The module used to instantiate this Instance.

pub fn context(&self) -> Ref<'_, Ctx>[src]

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

pub fn context_mut(&mut self) -> RefMut<'_, Ctx>[src]

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

pub fn exports(
    &self
) -> ExportsIterator<'_, impl Iterator<Item = (&String, &Extern)>>
[src]

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

Trait Implementations

impl LikeNamespace for Instance[src]

Auto Trait Implementations

impl !RefUnwindSafe for Instance

impl !Send for Instance

impl !Sync for Instance

impl Unpin for Instance

impl !UnwindSafe for Instance

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.