[][src]Struct wasmtime::Func

pub struct Func { /* fields omitted */ }

A WebAssembly function which can be called.

This type can represent a number of callable items, such as:

  • An exported function from a WebAssembly module.
  • A user-defined function used to satisfy an import.

These types of callable items are all wrapped up in this Func and can be used to both instantiate an Instance as well as be extracted from an Instance.

Func and Clone

Functions are internally reference counted so you can clone a Func. The cloning process only performs a shallow clone, so two cloned Func instances are equivalent in their functionality.

Methods

impl Func[src]

pub fn new(
    store: &Store,
    ty: FuncType,
    callable: Rc<dyn Callable + 'static>
) -> Self
[src]

Creates a new Func with the given arguments, typically to create a user-defined function to pass as an import to a module.

  • store - a cache of data where information is stored, typically shared with a Module.

  • ty - the signature of this function, used to indicate what the inputs and outputs are, which must be WebAssembly types.

  • callable - a type implementing the Callable trait which is the implementation of this Func value.

Note that the implementation of callable must adhere to the ty signature given, error or traps may occur if it does not respect the ty signature.

pub fn ty(&self) -> &FuncType[src]

Returns the underlying wasm type that this Func has.

pub fn param_arity(&self) -> usize[src]

Returns the number of parameters that this function takes.

pub fn result_arity(&self) -> usize[src]

Returns the number of results this function produces.

pub fn call(&self, params: &[Val]) -> Result<Box<[Val]>, Trap>[src]

Invokes this function with the params given, returning the results and any trap, if one occurs.

The params here must match the type signature of this Func, or a trap will occur. If a trap occurs while executing this function, then a trap will also be returned.

This function should not panic unless the underlying function itself initiates a panic.

Trait Implementations

impl Clone for Func[src]

impl Debug for Func[src]

impl From<Func> for Extern[src]

impl From<Func> for Val[src]

Auto Trait Implementations

impl !RefUnwindSafe for Func

impl !Send for Func

impl !Sync for Func

impl Unpin for Func

impl !UnwindSafe for Func

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.