pub fn typed<Params, Results, S>(&self, store: S) -> Result<TypedFunc<Params, Results>>
    where
        Params: WasmParams,
        Results: WasmResults,
        S: AsContext,
    {
        // Type-check that the params/results are all valid
        let ty = self.ty(store);
        Params::typecheck(ty.params()).context("type mismatch with parameters")?;
        Results::typecheck(ty.results()).context("type mismatch with results")?;

        // and then we can construct the typed version of this function
        // (unsafely), which should be safe since we just did the type check above.
        unsafe { Ok(TypedFunc::new_unchecked(*self)) }
    }
/// Attempts to extract a typed object from this `Func` through which the
/// function can be called.
///
/// This function serves as an alternative to [`Func::call`] and
/// [`Func::call_async`]. This method performs a static type check (using
/// the `Params` and `Results` type parameters on the underlying wasm
/// function. If the type check passes then a `TypedFunc` object is returned,
/// otherwise an error is returned describing the typecheck failure.
///
/// The purpose of this relative to [`Func::call`] is that it's much more
/// efficient when used to invoke WebAssembly functions. With the types
/// statically known far less setup/teardown is required when invoking
/// WebAssembly. If speed is desired then this function is recommended to be
/// used instead of [`Func::call`] (which is more general, hence its
/// slowdown).
///
/// The `Params` type parameter is used to describe the parameters of the
/// WebAssembly function. This can either be a single type (like `i32`), or
/// a tuple of types representing the list of parameters (like `(i32, f32,
/// f64)`). Additionally you can use `()` to represent that the function has
/// no parameters.
///
/// The `Results` type parameter is used to describe the results of the
/// function. This behaves the same way as `Params`, but just for the
/// results of the function.
///
/// The `S` type parameter represents the method of passing in the store
/// context, and can typically be specified as simply `_` when calling this
/// function.
///
/// Translation between Rust types and WebAssembly types looks like:
///
/// | WebAssembly | Rust                |
/// |-------------|---------------------|
/// | `i32`       | `i32` or `u32`      |
/// | `i64`       | `i64` or `u64`      |
/// | `f32`       | `f32`               |
/// | `f64`       | `f64`               |
/// | `externref` | `Option<ExternRef>` |
/// | `funcref`   | `Option<Func>`      |
/// | `v128`      | not supported       |
///
/// (note that this mapping is the same as that of [`Func::wrap`]).
///
/// Note that once the [`TypedFunc`] return value is acquired you'll use either
/// [`TypedFunc::call`] or [`TypedFunc::call_async`] as necessary to actually invoke
/// the function. This method does not invoke any WebAssembly code, it
/// simply performs a typecheck before returning the [`TypedFunc`] value.
///
/// This method also has a convenience wrapper as
/// [`Instance::get_typed_func`](crate::Instance::get_typed_func) to
/// directly get a typed function value from an
/// [`Instance`](crate::Instance).
///
/// # Errors
///
/// This function will return an error if `Params` or `Results` does not
/// match the native type of this WebAssembly function.
///
/// # Panics
///
/// This method will panic if `store` does not own this function.
///
/// # Examples
///
/// An end-to-end example of calling a function which takes no parameters
/// and has no results:
///
/// ```
/// # use wasmtime::*;
/// # fn main() -> anyhow::Result<()> {
/// let engine = Engine::default();
/// let mut store = Store::new(&engine, ());
/// let module = Module::new(&engine, r#"(module (func (export "foo")))"#)?;
/// let instance = Instance::new(&mut store, &module, &[])?;
/// let foo = instance.get_func(&mut store, "foo").expect("export wasn't a function");
///
/// // Note that this call can fail due to the typecheck not passing, but
/// // in our case we statically know the module so we know this should
/// // pass.
/// let typed = foo.typed::<(), (), _>(&store)?;
///
/// // Note that this can fail if the wasm traps at runtime.
/// typed.call(&mut store, ())?;
/// # Ok(())
/// # }
/// ```
///
/// You can also pass in multiple parameters and get a result back
///
/// ```
/// # use wasmtime::*;
/// # fn foo(add: &Func, mut store: Store<()>) -> anyhow::Result<()> {
/// let typed = add.typed::<(i32, i64), f32, _>(&store)?;
/// assert_eq!(typed.call(&mut store, (1, 2))?, 3.0);
/// # Ok(())
/// # }
/// ```
///
/// and similarly if a function has multiple results you can bind that too
///
/// ```
/// # #[cfg(not(feature = "old-x86-backend"))]
/// # use wasmtime::*;
/// # #[cfg(not(feature = "old-x86-backend"))]
/// # fn foo(add_with_overflow: &Func, mut store: Store<()>) -> anyhow::Result<()> {
/// let typed = add_with_overflow.typed::<(u32, u32), (u32, i32), _>(&store)?;
/// let (result, overflow) = typed.call(&mut store, (u32::max_value(), 2))?;
/// assert_eq!(result, 1);
/// assert_eq!(overflow, 1);
/// # Ok(())
/// # }
/// ```
Attempts to extract a typed object from this `Func` through which the
function can be called.

This function serves as an alternative to [`Func::call`] and
[`Func::call_async`]. This method performs a static type check (using
the `Params` and `Results` type parameters on the underlying wasm
function. If the type check passes then a `TypedFunc` object is returned,
otherwise an error is returned describing the typecheck failure.

The purpose of this relative to [`Func::call`] is that it's much more
efficient when used to invoke WebAssembly functions. With the types
statically known far less setup/teardown is required when invoking
WebAssembly. If speed is desired then this function is recommended to be
used instead of [`Func::call`] (which is more general, hence its
slowdown).

The `Params` type parameter is used to describe the parameters of the
WebAssembly function. This can either be a single type (like `i32`), or
a tuple of types representing the list of parameters (like `(i32, f32,
f64)`). Additionally you can use `()` to represent that the function has
no parameters.

The `Results` type parameter is used to describe the results of the
function. This behaves the same way as `Params`, but just for the
results of the function.

The `S` type parameter represents the method of passing in the store
context, and can typically be specified as simply `_` when calling this
function.

Translation between Rust types and WebAssembly types looks like.



(note that this mapping is the same as that of [`Func::wrap`]).




Attempts to extract a typed object from this ` Func ` through which the function can be called . This function serves as an alternative to [ ` Func :: call ` ] and [ ` Func :: call_async ` ] . This method performs a static type check ( using the ` Params ` and ` Results ` type parameters on the underlying wasm function . If the type check passes then a ` TypedFunc ` object is returned otherwise an error is returned describing the typecheck failure . The purpose of this relative to [ ` Func :: call ` ] is that it ' s much more efficient when used to invoke WebAssembly functions . With the types statically known far less setup / teardown is required when invoking WebAssembly . If speed is desired then this function is recommended to be used instead of [ ` Func :: call ` ] ( which is more general hence its slowdown ) . The ` Params ` type parameter is used to describe the parameters of the WebAssembly function . This can either be a single type ( like ` i32 ` ) or a tuple of types representing the list of parameters ( like ` ( i32 f32 f64 ) ` ) . Additionally you can use ` () ` to represent that the function has no parameters . The ` Results ` type parameter is used to describe the results of the function . This behaves the same way as ` Params ` but just for the results of the function . The ` S ` type parameter represents the method of passing in the store context and can typically be specified as simply ` _ ` when calling this function . Translation between Rust types and WebAssembly types looks like . ( note that this mapping is the same as that of [ ` Func :: wrap ` ] ) .
pub fn typed<Params, Results, S>(&self, store: S) -> Result<TypedFunc<Params, Results>>
    where
        Params: WasmParams,
        Results: WasmResults,
        S: AsContext,
    {
        // Type-check that the params/results are all valid
        let ty = self.ty(store);
        Params::typecheck(ty.params()).context("type mismatch with parameters")?;
        Results::typecheck(ty.results()).context("type mismatch with results")?;
        // and then we can construct the typed version of this function
        // (unsafely), which should be safe since we just did the type check above.
        unsafe { Ok(TypedFunc::new_unchecked(*self)) }
    }
pub fn typed < Params , Results , S > ( & self , store : S ) -> Result < TypedFunc < Params , Results > > where Params : WasmParams , Results : WasmResults , S : AsContext , { // Type-check that the params/results are all valid let ty = self . ty ( store ) ; Params :: typecheck ( ty . params ( ) ) . context ( " " ) ? ; Results :: typecheck ( ty . results ( ) ) . context ( " " ) ? ; // and then we can construct the typed version of this function // (unsafely), which should be safe since we just did the type check above. unsafe { Ok ( TypedFunc :: new_unchecked ( * self ) ) } }
Attempts to extract a typed object from this `Func` through which the
function can be called.
Attempts to extract a typed object from this ` Func ` through which the function can be called .
&self
store
S
&self
store
S
errors
This function will return an error if `Params` or `Results` does not
match the native type of this WebAssembly function.
This function will return an error if ` Params ` or ` Results ` does not match the native type of this WebAssembly function .
panics
This method will panic if `store` does not own this function.
This method will panic if ` store ` does not own this function .
examples
An end-to-end example of calling a function which takes no parameters
and has no results.


An end - to - end example of calling a function which takes no parameters and has no results .
use wasmtime::*;
None
fn main() -> anyhow::result<()> {
let engine = Engine::default();
let mut store = Store::new(&engine, ());
let module = Module::new(&engine, r#"(module (func (export "foo")))"#)?;
let instance = Instance::new(&mut store, &module, &[])?;
let foo = instance.get_func(&mut store, "foo").expect("export wasn't a function").

Note that this call can fail due to the typecheck not passing, but
in our case we statically know the module so we know this should
pass.

Note that this can fail if the wasm traps at runtime.
typed.call(&mut store, ())?.
let engine = Engine :: default () ; let mut store = Store :: new ( &engine () ) ; let module = Module :: new ( &engine r# " ( module ( func ( export " foo " ))) " # ) ? ; let instance = Instance :: new ( &mut store &module & [] ) ? ; let foo = instance . get_func ( &mut store " foo " ) . expect ( " export wasn ' t a function " ) . Note that this call can fail due to the typecheck not passing but in our case we statically know the module so we know this should pass . Note that this can fail if the wasm traps at runtime . typed . call ( &mut store () ) ? .
ok(())
None
}


You can also pass in multiple parameters and get a result back


You can also pass in multiple parameters and get a result back
use wasmtime::*;
None
fn foo(add: &func, mut store: store<()>) -> anyhow::result<()> {
None
ok(())
None
}


and similarly if a function has multiple results you can bind that too


and similarly if a function has multiple results you can bind that too
#[cfg(not(feature = "old-x86-backend"))]
None
use wasmtime::*;
None
#[cfg(not(feature = "old-x86-backend"))]
None
fn foo(add_with_overflow: &func, mut store: store<()>) -> anyhow::result<()> {
None
ok(())
None
}
None