pub struct Foo { new: wasmtime::component::Func, } const _: () = { #[allow(unused_imports)] use wasmtime::component::__internal::anyhow; impl Foo { /// Instantiates the provided `module` using the specified /// parameters, wrapping up the result in a structure that /// translates between wasm and the host. pub async fn instantiate_async( mut store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker, ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { let instance = linker.instantiate_async(&mut store, component).await?; Ok((Self::new(store, &instance)?, instance)) } /// Instantiates a pre-instantiated module using the specified /// parameters, wrapping up the result in a structure that /// translates between wasm and the host. pub async fn instantiate_pre( mut store: impl wasmtime::AsContextMut, instance_pre: &wasmtime::component::InstancePre, ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> { let instance = instance_pre.instantiate_async(&mut store).await?; Ok((Self::new(store, &instance)?, instance)) } /// Low-level creation wrapper for wrapping up the exports /// of the `instance` provided in this structure of wasm /// exports. /// /// This function will extract exports from the `instance` /// defined within `store` and wrap them all up in the /// returned structure which can be used to interact with /// the wasm module. pub fn new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result { let mut store = store.as_context_mut(); let mut exports = instance.exports(&mut store); let mut __exports = exports.root(); let new = *__exports.typed_func::<(), ()>("new")?.func(); Ok(Foo { new }) } pub async fn call_new( &self, mut store: S, ) -> wasmtime::Result<()> where ::Data: Send, { let callee = unsafe { wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new) }; let () = callee.call_async(store.as_context_mut(), ()).await?; callee.post_return_async(store.as_context_mut()).await?; Ok(()) } } };