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

Method try_wrap

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

Fallible version of [`Func::wrap`] that returns an error on out-of-memory instead of panicking. # Errors This function will return an [`OutOfMemory`][crate::OutOfMemory] error when memory allocation fails. See the `OutOfMemory` type's documentation for details on Wasmtime's out-of-memory handling.

(
        mut store: impl AsContextMut<Data = T>,
        func: impl IntoFunc<T, Params, Results>,
    )

Source from the content-addressed store, hash-verified

827 /// memory allocation fails. See the `OutOfMemory` type's documentation for
828 /// details on Wasmtime's out-of-memory handling.
829 pub fn try_wrap<T, Params, Results>(
830 mut store: impl AsContextMut<Data = T>,
831 func: impl IntoFunc<T, Params, Results>,
832 ) -> Result<Func>
833 where
834 T: 'static,
835 {
836 let store = store.as_context_mut().0;
837 let engine = store.engine();
838 let host = func.into_func(engine)?;
839
840 // SAFETY: The `T` the closure takes is the same as the `T` of the store
841 // we're inserting into via the type signature above.
842 Ok(unsafe { host.into_func(store)? })
843 }
844
845 /// Same as [`Func::wrap`], except the closure asynchronously produces the
846 /// result and the arguments are passed within a tuple. For more information

Callers

nothing calls this directly

Calls 4

OkFunction · 0.85
as_context_mutMethod · 0.45
engineMethod · 0.45
into_funcMethod · 0.45

Tested by

no test coverage detected