1 pub struct Imports {}
2 const _: () = {
3     #[allow(unused_imports)]
4     use wasmtime::component::__internal::anyhow;
5     impl Imports {
6         pub fn add_to_linker<T, U>(
7             linker: &mut wasmtime::component::Linker<T>,
8             get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
9         ) -> wasmtime::Result<()>
10         where
11             T: Send,
12             U: a::b::interface_with_live_type::Host
13                 + a::b::interface_with_dead_type::Host + Send,
14         {
15             a::b::interface_with_live_type::add_to_linker(linker, get)?;
16             a::b::interface_with_dead_type::add_to_linker(linker, get)?;
17             Ok(())
18         }
19         /// Instantiates the provided `module` using the specified
20         /// parameters, wrapping up the result in a structure that
21         /// translates between wasm and the host.
22         pub async fn instantiate_async<T: Send>(
23             mut store: impl wasmtime::AsContextMut<Data = T>,
24             component: &wasmtime::component::Component,
25             linker: &wasmtime::component::Linker<T>,
26         ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {
27             let instance = linker.instantiate_async(&mut store, component).await?;
28             Ok((Self::new(store, &instance)?, instance))
29         }
30         /// Instantiates a pre-instantiated module using the specified
31         /// parameters, wrapping up the result in a structure that
32         /// translates between wasm and the host.
33         pub async fn instantiate_pre<T: Send>(
34             mut store: impl wasmtime::AsContextMut<Data = T>,
35             instance_pre: &wasmtime::component::InstancePre<T>,
36         ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {
37             let instance = instance_pre.instantiate_async(&mut store).await?;
38             Ok((Self::new(store, &instance)?, instance))
39         }
40         /// Low-level creation wrapper for wrapping up the exports
41         /// of the `instance` provided in this structure of wasm
42         /// exports.
43         ///
44         /// This function will extract exports from the `instance`
45         /// defined within `store` and wrap them all up in the
46         /// returned structure which can be used to interact with
47         /// the wasm module.
48         pub fn new(
49             mut store: impl wasmtime::AsContextMut,
50             instance: &wasmtime::component::Instance,
51         ) -> wasmtime::Result<Self> {
52             let mut store = store.as_context_mut();
53             let mut exports = instance.exports(&mut store);
54             let mut __exports = exports.root();
55             Ok(Imports {})
56         }
57     }
58 };
59 pub mod a {
60     pub mod b {
61         #[allow(clippy::all)]
62         pub mod interface_with_live_type {
63             #[allow(unused_imports)]
64             use wasmtime::component::__internal::anyhow;
65             #[derive(wasmtime::component::ComponentType)]
66             #[derive(wasmtime::component::Lift)]
67             #[derive(wasmtime::component::Lower)]
68             #[component(record)]
69             #[derive(Clone, Copy)]
70             pub struct LiveType {
71                 #[component(name = "a")]
72                 pub a: u32,
73             }
74             impl core::fmt::Debug for LiveType {
75                 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
76                     f.debug_struct("LiveType").field("a", &self.a).finish()
77                 }
78             }
79             const _: () = {
80                 assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32);
81                 assert!(
82                     4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32
83                 );
84             };
85             #[wasmtime::component::__internal::async_trait]
86             pub trait Host: Send {
87                 async fn f(&mut self) -> LiveType;
88             }
89             pub trait GetHost<
90                 T,
91             >: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
92                 type Host: Host + Send;
93             }
94             impl<F, T, O> GetHost<T> for F
95             where
96                 F: Fn(T) -> O + Send + Sync + Copy + 'static,
97                 O: Host + Send,
98             {
99                 type Host = O;
100             }
101             pub fn add_to_linker_get_host<T>(
102                 linker: &mut wasmtime::component::Linker<T>,
103                 host_getter: impl for<'a> GetHost<&'a mut T>,
104             ) -> wasmtime::Result<()>
105             where
106                 T: Send,
107             {
108                 let mut inst = linker.instance("a:b/interface-with-live-type")?;
109                 inst.func_wrap_async(
110                     "f",
111                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| wasmtime::component::__internal::Box::new(async move {
112                         let host = &mut host_getter(caller.data_mut());
113                         let r = Host::f(host).await;
114                         Ok((r,))
115                     }),
116                 )?;
117                 Ok(())
118             }
119             pub fn add_to_linker<T, U>(
120                 linker: &mut wasmtime::component::Linker<T>,
121                 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
122             ) -> wasmtime::Result<()>
123             where
124                 U: Host + Send,
125                 T: Send,
126             {
127                 add_to_linker_get_host(linker, get)
128             }
129             #[wasmtime::component::__internal::async_trait]
130             impl<_T: Host + ?Sized + Send> Host for &mut _T {
131                 async fn f(&mut self) -> LiveType {
132                     Host::f(*self).await
133                 }
134             }
135         }
136         #[allow(clippy::all)]
137         pub mod interface_with_dead_type {
138             #[allow(unused_imports)]
139             use wasmtime::component::__internal::anyhow;
140             #[wasmtime::component::__internal::async_trait]
141             pub trait Host: Send {}
142             pub trait GetHost<
143                 T,
144             >: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
145                 type Host: Host + Send;
146             }
147             impl<F, T, O> GetHost<T> for F
148             where
149                 F: Fn(T) -> O + Send + Sync + Copy + 'static,
150                 O: Host + Send,
151             {
152                 type Host = O;
153             }
154             pub fn add_to_linker_get_host<T>(
155                 linker: &mut wasmtime::component::Linker<T>,
156                 host_getter: impl for<'a> GetHost<&'a mut T>,
157             ) -> wasmtime::Result<()>
158             where
159                 T: Send,
160             {
161                 let mut inst = linker.instance("a:b/interface-with-dead-type")?;
162                 Ok(())
163             }
164             pub fn add_to_linker<T, U>(
165                 linker: &mut wasmtime::component::Linker<T>,
166                 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
167             ) -> wasmtime::Result<()>
168             where
169                 U: Host + Send,
170                 T: Send,
171             {
172                 add_to_linker_get_host(linker, get)
173             }
174             #[wasmtime::component::__internal::async_trait]
175             impl<_T: Host + ?Sized + Send> Host for &mut _T {}
176         }
177     }
178 }
179