1 /// Auto-generated bindings for a pre-instantiated version of a
2 /// component which implements the world `example`.
3 ///
4 /// This structure is created through [`ExamplePre::new`] which
5 /// takes a [`InstancePre`](wasmtime::component::InstancePre) that
6 /// has been created through a [`Linker`](wasmtime::component::Linker).
7 ///
8 /// For more information see [`Example`] as well.
9 pub struct ExamplePre<T: 'static> {
10     instance_pre: wasmtime::component::InstancePre<T>,
11     indices: ExampleIndices,
12 }
13 impl<T: 'static> Clone for ExamplePre<T> {
clone(&self) -> Self14     fn clone(&self) -> Self {
15         Self {
16             instance_pre: self.instance_pre.clone(),
17             indices: self.indices.clone(),
18         }
19     }
20 }
21 impl<_T: 'static> ExamplePre<_T> {
22     /// Creates a new copy of `ExamplePre` bindings which can then
23     /// be used to instantiate into a particular store.
24     ///
25     /// This method may fail if the component behind `instance_pre`
26     /// does not have the required exports.
new( instance_pre: wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>27     pub fn new(
28         instance_pre: wasmtime::component::InstancePre<_T>,
29     ) -> wasmtime::Result<Self> {
30         let indices = ExampleIndices::new(&instance_pre)?;
31         Ok(Self { instance_pre, indices })
32     }
engine(&self) -> &wasmtime::Engine33     pub fn engine(&self) -> &wasmtime::Engine {
34         self.instance_pre.engine()
35     }
instance_pre(&self) -> &wasmtime::component::InstancePre<_T>36     pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
37         &self.instance_pre
38     }
39     /// Instantiates a new instance of [`Example`] within the
40     /// `store` provided.
41     ///
42     /// This function will use `self` as the pre-instantiated
43     /// instance to perform instantiation. Afterwards the preloaded
44     /// indices in `self` are used to lookup all exports on the
45     /// resulting instance.
instantiate( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<Example>46     pub fn instantiate(
47         &self,
48         mut store: impl wasmtime::AsContextMut<Data = _T>,
49     ) -> wasmtime::Result<Example> {
50         let mut store = store.as_context_mut();
51         let instance = self.instance_pre.instantiate(&mut store)?;
52         self.indices.load(&mut store, &instance)
53     }
54 }
55 impl<_T: Send + 'static> ExamplePre<_T> {
56     /// Same as [`Self::instantiate`], except with `async`.
instantiate_async( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<Example>57     pub async fn instantiate_async(
58         &self,
59         mut store: impl wasmtime::AsContextMut<Data = _T>,
60     ) -> wasmtime::Result<Example> {
61         let mut store = store.as_context_mut();
62         let instance = self.instance_pre.instantiate_async(&mut store).await?;
63         self.indices.load(&mut store, &instance)
64     }
65 }
66 /// Auto-generated bindings for index of the exports of
67 /// `example`.
68 ///
69 /// This is an implementation detail of [`ExamplePre`] and can
70 /// be constructed if needed as well.
71 ///
72 /// For more information see [`Example`] as well.
73 #[derive(Clone)]
74 pub struct ExampleIndices {
75     interface0: exports::same::name::this_name_is_duplicated::GuestIndices,
76 }
77 /// Auto-generated bindings for an instance a component which
78 /// implements the world `example`.
79 ///
80 /// This structure can be created through a number of means
81 /// depending on your requirements and what you have on hand:
82 ///
83 /// * The most convenient way is to use
84 ///   [`Example::instantiate`] which only needs a
85 ///   [`Store`], [`Component`], and [`Linker`].
86 ///
87 /// * Alternatively you can create a [`ExamplePre`] ahead of
88 ///   time with a [`Component`] to front-load string lookups
89 ///   of exports once instead of per-instantiation. This
90 ///   method then uses [`ExamplePre::instantiate`] to
91 ///   create a [`Example`].
92 ///
93 /// * If you've instantiated the instance yourself already
94 ///   then you can use [`Example::new`].
95 ///
96 /// These methods are all equivalent to one another and move
97 /// around the tradeoff of what work is performed when.
98 ///
99 /// [`Store`]: wasmtime::Store
100 /// [`Component`]: wasmtime::component::Component
101 /// [`Linker`]: wasmtime::component::Linker
102 pub struct Example {
103     interface0: exports::same::name::this_name_is_duplicated::Guest,
104 }
105 const _: () = {
106     impl ExampleIndices {
107         /// Creates a new copy of `ExampleIndices` bindings which can then
108         /// be used to instantiate into a particular store.
109         ///
110         /// This method may fail if the component does not have the
111         /// required exports.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>112         pub fn new<_T>(
113             _instance_pre: &wasmtime::component::InstancePre<_T>,
114         ) -> wasmtime::Result<Self> {
115             let _component = _instance_pre.component();
116             let _instance_type = _instance_pre.instance_type();
117             let interface0 = exports::same::name::this_name_is_duplicated::GuestIndices::new(
118                 _instance_pre,
119             )?;
120             Ok(ExampleIndices { interface0 })
121         }
122         /// Uses the indices stored in `self` to load an instance
123         /// of [`Example`] from the instance provided.
124         ///
125         /// Note that at this time this method will additionally
126         /// perform type-checks of all exports.
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Example>127         pub fn load(
128             &self,
129             mut store: impl wasmtime::AsContextMut,
130             instance: &wasmtime::component::Instance,
131         ) -> wasmtime::Result<Example> {
132             let _ = &mut store;
133             let _instance = instance;
134             let interface0 = self.interface0.load(&mut store, &_instance)?;
135             Ok(Example { interface0 })
136         }
137     }
138     impl Example {
139         /// Convenience wrapper around [`ExamplePre::new`] and
140         /// [`ExamplePre::instantiate`].
instantiate<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<Example>141         pub fn instantiate<_T>(
142             store: impl wasmtime::AsContextMut<Data = _T>,
143             component: &wasmtime::component::Component,
144             linker: &wasmtime::component::Linker<_T>,
145         ) -> wasmtime::Result<Example> {
146             let pre = linker.instantiate_pre(component)?;
147             ExamplePre::new(pre)?.instantiate(store)
148         }
149         /// Convenience wrapper around [`ExampleIndices::new`] and
150         /// [`ExampleIndices::load`].
new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Example>151         pub fn new(
152             mut store: impl wasmtime::AsContextMut,
153             instance: &wasmtime::component::Instance,
154         ) -> wasmtime::Result<Example> {
155             let indices = ExampleIndices::new(&instance.instance_pre(&store))?;
156             indices.load(&mut store, instance)
157         }
158         /// Convenience wrapper around [`ExamplePre::new`] and
159         /// [`ExamplePre::instantiate_async`].
instantiate_async<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<Example> where _T: Send,160         pub async fn instantiate_async<_T>(
161             store: impl wasmtime::AsContextMut<Data = _T>,
162             component: &wasmtime::component::Component,
163             linker: &wasmtime::component::Linker<_T>,
164         ) -> wasmtime::Result<Example>
165         where
166             _T: Send,
167         {
168             let pre = linker.instantiate_pre(component)?;
169             ExamplePre::new(pre)?.instantiate_async(store).await
170         }
same_name_this_name_is_duplicated( &self, ) -> &exports::same::name::this_name_is_duplicated::Guest171         pub fn same_name_this_name_is_duplicated(
172             &self,
173         ) -> &exports::same::name::this_name_is_duplicated::Guest {
174             &self.interface0
175         }
176     }
177 };
178 pub mod exports {
179     pub mod same {
180         pub mod name {
181             #[allow(clippy::all)]
182             pub mod this_name_is_duplicated {
183                 #[allow(unused_imports)]
184                 use wasmtime::component::__internal::Box;
185                 pub type ThisNameIsDuplicated = wasmtime::component::ResourceAny;
186                 pub struct GuestThisNameIsDuplicated<'a> {
187                     funcs: &'a Guest,
188                 }
189                 #[derive(Clone)]
190                 pub struct Guest {}
191                 #[derive(Clone)]
192                 pub struct GuestIndices {}
193                 impl GuestIndices {
194                     /// Constructor for [`GuestIndices`] which takes a
195                     /// [`Component`](wasmtime::component::Component) as input and can be executed
196                     /// before instantiation.
197                     ///
198                     /// This constructor can be used to front-load string lookups to find exports
199                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>200                     pub fn new<_T>(
201                         _instance_pre: &wasmtime::component::InstancePre<_T>,
202                     ) -> wasmtime::Result<GuestIndices> {
203                         let instance = _instance_pre
204                             .component()
205                             .get_export_index(None, "same:name/this-name-is-duplicated")
206                             .ok_or_else(|| {
207                                 wasmtime::format_err!(
208                                     "no exported instance named `same:name/this-name-is-duplicated`"
209                                 )
210                             })?;
211                         let mut lookup = move |name| {
212                             _instance_pre
213                                 .component()
214                                 .get_export_index(Some(&instance), name)
215                                 .ok_or_else(|| {
216                                     wasmtime::format_err!(
217                                         "instance export `same:name/this-name-is-duplicated` does \
218                 not have export `{name}`"
219                                     )
220                                 })
221                         };
222                         let _ = &mut lookup;
223                         Ok(GuestIndices {})
224                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>225                     pub fn load(
226                         &self,
227                         mut store: impl wasmtime::AsContextMut,
228                         instance: &wasmtime::component::Instance,
229                     ) -> wasmtime::Result<Guest> {
230                         let _instance = instance;
231                         let _instance_pre = _instance.instance_pre(&store);
232                         let _instance_type = _instance_pre.instance_type();
233                         let mut store = store.as_context_mut();
234                         let _ = &mut store;
235                         Ok(Guest {})
236                     }
237                 }
238                 impl Guest {}
239             }
240         }
241     }
242 }
243