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

Method resource

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

Defines a new resource of a given [`ResourceType`] in this linker. This function is used to specify resources defined in the host. The `name` argument is the name to define the resource within this linker. The `dtor` provided is a destructor that will get invoked when an owned version of this resource is destroyed from the guest. Note that this destructor is not called when a host-owned resourc

(
        &mut self,
        name: &str,
        ty: ResourceType,
        dtor: impl Fn(StoreContextMut<'_, T>, u32) -> Result<()> + Send + Sync + 'static,
    )

Source from the content-addressed store, hash-verified

803 /// memory allocation fails. See the `OutOfMemory` type's documentation for
804 /// details on Wasmtime's out-of-memory handling.
805 pub fn resource(
806 &mut self,
807 name: &str,
808 ty: ResourceType,
809 dtor: impl Fn(StoreContextMut<'_, T>, u32) -> Result<()> + Send + Sync + 'static,
810 ) -> Result<()> {
811 let dtor = try_new::<Arc<_>>(crate::func::HostFunc::wrap(
812 &self.engine,
813 move |mut cx: crate::Caller<'_, T>, (param,): (u32,)| dtor(cx.as_context_mut(), param),
814 )?)?;
815 self.insert(name, Definition::Resource(ty, dtor))?;
816 Ok(())
817 }
818
819 /// Identical to [`Self::resource`], except that it takes an async destructor.
820 #[cfg(feature = "async")]

Callers 15

introspectionFunction · 0.45
host_resource_typesFunction · 0.45
drop_host_twiceFunction · 0.45
manually_destroyFunction · 0.45
dynamic_typeFunction · 0.45
dynamic_valFunction · 0.45
thread_through_borrowFunction · 0.45
can_use_own_for_borrowFunction · 0.45

Calls 4

OkFunction · 0.85
ResourceClass · 0.50
as_context_mutMethod · 0.45
insertMethod · 0.45

Tested by 15

introspectionFunction · 0.36
host_resource_typesFunction · 0.36
drop_host_twiceFunction · 0.36
manually_destroyFunction · 0.36
dynamic_typeFunction · 0.36
dynamic_valFunction · 0.36
thread_through_borrowFunction · 0.36
can_use_own_for_borrowFunction · 0.36