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

Method func_new

crates/wasmtime/src/runtime/component/linker.rs:700–710  ·  view source on GitHub ↗

Define a new host-provided function using dynamically typed values. The `name` provided is the name of the function to define and the `func` provided is the host-defined closure to invoke when this function is called. This function is the "dynamic" version of defining a host function as compared to [`LinkerInstance::func_wrap`]. With [`LinkerInstance::func_wrap`] a function's type is statically

(
        &mut self,
        name: &str,
        func: impl Fn(StoreContextMut<'_, T>, types::ComponentFunc, &[Val], &mut [Val]) -> Result<()>
        + Send
        + Sync
        + 'static,
    )

Source from the content-addressed store, hash-verified

698 /// memory allocation fails. See the `OutOfMemory` type's documentation for
699 /// details on Wasmtime's out-of-memory handling.
700 pub fn func_new(
701 &mut self,
702 name: &str,
703 func: impl Fn(StoreContextMut<'_, T>, types::ComponentFunc, &[Val], &mut [Val]) -> Result<()>
704 + Send
705 + Sync
706 + 'static,
707 ) -> Result<()> {
708 self.insert(name, Definition::Func(HostFunc::func_new(func)?))?;
709 Ok(())
710 }
711
712 /// Define a new host-provided async function using dynamic types.
713 ///

Callers 1

stub_itemMethod · 0.45

Calls 4

func_newFunction · 0.85
OkFunction · 0.85
FuncClass · 0.70
insertMethod · 0.45

Tested by

no test coverage detected