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

Method new_unchecked

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

Creates a new [`Func`] with the given arguments, although has fewer runtime checks than [`Func::new`]. This function takes a callback of a different signature than [`Func::new`], instead receiving a raw pointer with a list of [`ValRaw`] structures. These values have no type information associated with them so it's up to the caller to provide a function that will correctly interpret the list of va

(
        mut store: impl AsContextMut<Data = T>,
        ty: FuncType,
        func: impl Fn(Caller<'_, T>, &mut [MaybeUninit<ValRaw>]) -> Result<()> + Send + Sync + 'static,
    )

Source from the content-addressed store, hash-verified

437 /// Panics if the given function type is not associated with this store's
438 /// engine.
439 pub unsafe fn new_unchecked<T: 'static>(
440 mut store: impl AsContextMut<Data = T>,
441 ty: FuncType,
442 func: impl Fn(Caller<'_, T>, &mut [MaybeUninit<ValRaw>]) -> Result<()> + Send + Sync + 'static,
443 ) -> Self {
444 let store = store.as_context_mut().0;
445
446 // SAFETY: the contract required by `new_unchecked` is the same as the
447 // contract required by this function itself.
448 let host = unsafe { HostFunc::new_unchecked(store.engine(), ty, func).panic_on_oom() };
449
450 // SAFETY: the `T` used by `func` matches the `T` of the store we're
451 // inserting into via this function's type signature.
452 unsafe { host.into_func(store).panic_on_oom() }
453 }
454
455 /// Creates a new host-defined WebAssembly function which, when called,
456 /// will run the asynchronous computation defined by `func` to completion

Callers

nothing calls this directly

Calls 5

OkFunction · 0.85
panic_on_oomMethod · 0.80
as_context_mutMethod · 0.45
engineMethod · 0.45
into_funcMethod · 0.45

Tested by

no test coverage detected