Class: Wasmtime::Component::Instance

Inherits:
Object
  • Object
show all
Defined in:
ext/src/ruby_api/component/instance.rs

Overview

Represents a WebAssembly component instance.

Instance Method Summary collapse

Instance Method Details

#get_func(handle) ⇒ Func?

Retrieves a Wasm function from the component instance.

Examples:

Retrieve a top-level add export:

instance.get_func("add")

Retrieve an add export nested under an adder instance top-level export:

instance.get_func(["adder", "add"])

Parameters:

  • handle (String, Array<String>)

    The path of the function to retrieve

Returns:

  • (Func, nil)

    The function if it exists, nil otherwise



57
58
59
60
61
62
63
64
# File 'ext/src/ruby_api/component/instance.rs', line 57

pub fn get_func(rb_self: Obj<Self>, handle: Value) -> Result<Option<Func>, Error> {
    let func = rb_self
        .export_index(handle)?
        .and_then(|index| rb_self.inner.get_func(rb_self.store.context_mut(), index))
        .map(|inner| Func::from_inner(inner, rb_self, rb_self.store));

    Ok(func)
}