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 des
(
&self,
store: impl AsContext,
)
| 1412 | /// # } |
| 1413 | /// ``` |
| 1414 | pub fn typed<Params, Results>( |
| 1415 | &self, |
| 1416 | store: impl AsContext, |
| 1417 | ) -> Result<TypedFunc<Params, Results>> |
| 1418 | where |
| 1419 | Params: WasmParams, |
| 1420 | Results: WasmResults, |
| 1421 | { |
| 1422 | // Type-check that the params/results are all valid |
| 1423 | let store = store.as_context().0; |
| 1424 | let ty = self.load_ty(store); |
| 1425 | Params::typecheck(store.engine(), ty.params(), TypeCheckPosition::Param) |
| 1426 | .context("type mismatch with parameters")?; |
| 1427 | Results::typecheck(store.engine(), ty.results(), TypeCheckPosition::Result) |
| 1428 | .context("type mismatch with results")?; |
| 1429 | |
| 1430 | // and then we can construct the typed version of this function |
| 1431 | // (unsafely), which should be safe since we just did the type check above. |
| 1432 | unsafe { Ok(TypedFunc::_new_unchecked(store, *self)) } |
| 1433 | } |
| 1434 | |
| 1435 | /// Get a stable hash key for this function. |
| 1436 | /// |
no test coverage detected