1 pub struct Foo {
2     new: wasmtime::component::Func,
3 }
4 const _: () = {
5     #[allow(unused_imports)]
6     use wasmtime::component::__internal::anyhow;
7     impl Foo {
8         /// Instantiates the provided `module` using the specified
9         /// parameters, wrapping up the result in a structure that
10         /// translates between wasm and the host.
11         pub fn instantiate<T>(
12             mut store: impl wasmtime::AsContextMut<Data = T>,
13             component: &wasmtime::component::Component,
14             linker: &wasmtime::component::Linker<T>,
15         ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {
16             let instance = linker.instantiate(&mut store, component)?;
17             Ok((Self::new(store, &instance)?, instance))
18         }
19         /// Instantiates a pre-instantiated module using the specified
20         /// parameters, wrapping up the result in a structure that
21         /// translates between wasm and the host.
22         pub fn instantiate_pre<T>(
23             mut store: impl wasmtime::AsContextMut<Data = T>,
24             instance_pre: &wasmtime::component::InstancePre<T>,
25         ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {
26             let instance = instance_pre.instantiate(&mut store)?;
27             Ok((Self::new(store, &instance)?, instance))
28         }
29         /// Low-level creation wrapper for wrapping up the exports
30         /// of the `instance` provided in this structure of wasm
31         /// exports.
32         ///
33         /// This function will extract exports from the `instance`
34         /// defined within `store` and wrap them all up in the
35         /// returned structure which can be used to interact with
36         /// the wasm module.
37         pub fn new(
38             mut store: impl wasmtime::AsContextMut,
39             instance: &wasmtime::component::Instance,
40         ) -> wasmtime::Result<Self> {
41             let mut store = store.as_context_mut();
42             let mut exports = instance.exports(&mut store);
43             let mut __exports = exports.root();
44             let new = *__exports.typed_func::<(), ()>("new")?.func();
45             Ok(Foo { new })
46         }
47         pub fn call_new<S: wasmtime::AsContextMut>(
48             &self,
49             mut store: S,
50         ) -> wasmtime::Result<()> {
51             let callee = unsafe {
52                 wasmtime::component::TypedFunc::<(), ()>::new_unchecked(self.new)
53             };
54             let () = callee.call(store.as_context_mut(), ())?;
55             callee.post_return(store.as_context_mut())?;
56             Ok(())
57         }
58     }
59 };
60