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