MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / typed

Method typed

crates/wasmtime/src/runtime/func.rs:1414–1433  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers 1

find_funcsFunction · 0.45

Calls 8

OkFunction · 0.85
typecheckFunction · 0.70
as_contextMethod · 0.45
load_tyMethod · 0.45
contextMethod · 0.45
engineMethod · 0.45
paramsMethod · 0.45
resultsMethod · 0.45

Tested by

no test coverage detected