[−][src]Struct wasmtime::Func
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]
store: &Store,
ty: FuncType,
callable: Rc<dyn Callable + 'static>
) -> Self
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 aModule
. -
ty
- the signature of this function, used to indicate what the inputs and outputs are, which must be WebAssembly types. -
callable
- a type implementing theCallable
trait which is the implementation of thisFunc
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,