1 /// Auto-generated bindings for a pre-instantiated version of a
2 /// component which implements the world `w`.
3 ///
4 /// This structure is created through [`WPre::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 [`W`] as well.
9 pub struct WPre<T: 'static> {
10     instance_pre: wasmtime::component::InstancePre<T>,
11     indices: WIndices,
12 }
13 impl<T: 'static> Clone for WPre<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> WPre<_T> {
22     /// Creates a new copy of `WPre` 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 = WIndices::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 [`W`] 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<W>46     pub fn instantiate(
47         &self,
48         mut store: impl wasmtime::AsContextMut<Data = _T>,
49     ) -> wasmtime::Result<W> {
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> WPre<_T> {
56     /// Same as [`Self::instantiate`], except with `async`.
instantiate_async( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<W>57     pub async fn instantiate_async(
58         &self,
59         mut store: impl wasmtime::AsContextMut<Data = _T>,
60     ) -> wasmtime::Result<W> {
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 /// `w`.
68 ///
69 /// This is an implementation detail of [`WPre`] and can
70 /// be constructed if needed as well.
71 ///
72 /// For more information see [`W`] as well.
73 #[derive(Clone)]
74 pub struct WIndices {
75     interface0: exports::foo::foo::simple_export::GuestIndices,
76     interface1: exports::foo::foo::export_using_import::GuestIndices,
77     interface2: exports::foo::foo::export_using_export1::GuestIndices,
78     interface3: exports::foo::foo::export_using_export2::GuestIndices,
79 }
80 /// Auto-generated bindings for an instance a component which
81 /// implements the world `w`.
82 ///
83 /// This structure can be created through a number of means
84 /// depending on your requirements and what you have on hand:
85 ///
86 /// * The most convenient way is to use
87 ///   [`W::instantiate`] which only needs a
88 ///   [`Store`], [`Component`], and [`Linker`].
89 ///
90 /// * Alternatively you can create a [`WPre`] ahead of
91 ///   time with a [`Component`] to front-load string lookups
92 ///   of exports once instead of per-instantiation. This
93 ///   method then uses [`WPre::instantiate`] to
94 ///   create a [`W`].
95 ///
96 /// * If you've instantiated the instance yourself already
97 ///   then you can use [`W::new`].
98 ///
99 /// These methods are all equivalent to one another and move
100 /// around the tradeoff of what work is performed when.
101 ///
102 /// [`Store`]: wasmtime::Store
103 /// [`Component`]: wasmtime::component::Component
104 /// [`Linker`]: wasmtime::component::Linker
105 pub struct W {
106     interface0: exports::foo::foo::simple_export::Guest,
107     interface1: exports::foo::foo::export_using_import::Guest,
108     interface2: exports::foo::foo::export_using_export1::Guest,
109     interface3: exports::foo::foo::export_using_export2::Guest,
110 }
111 const _: () = {
112     impl WIndices {
113         /// Creates a new copy of `WIndices` bindings which can then
114         /// be used to instantiate into a particular store.
115         ///
116         /// This method may fail if the component does not have the
117         /// required exports.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>118         pub fn new<_T>(
119             _instance_pre: &wasmtime::component::InstancePre<_T>,
120         ) -> wasmtime::Result<Self> {
121             let _component = _instance_pre.component();
122             let _instance_type = _instance_pre.instance_type();
123             let interface0 = exports::foo::foo::simple_export::GuestIndices::new(
124                 _instance_pre,
125             )?;
126             let interface1 = exports::foo::foo::export_using_import::GuestIndices::new(
127                 _instance_pre,
128             )?;
129             let interface2 = exports::foo::foo::export_using_export1::GuestIndices::new(
130                 _instance_pre,
131             )?;
132             let interface3 = exports::foo::foo::export_using_export2::GuestIndices::new(
133                 _instance_pre,
134             )?;
135             Ok(WIndices {
136                 interface0,
137                 interface1,
138                 interface2,
139                 interface3,
140             })
141         }
142         /// Uses the indices stored in `self` to load an instance
143         /// of [`W`] from the instance provided.
144         ///
145         /// Note that at this time this method will additionally
146         /// perform type-checks of all exports.
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<W>147         pub fn load(
148             &self,
149             mut store: impl wasmtime::AsContextMut,
150             instance: &wasmtime::component::Instance,
151         ) -> wasmtime::Result<W> {
152             let _ = &mut store;
153             let _instance = instance;
154             let interface0 = self.interface0.load(&mut store, &_instance)?;
155             let interface1 = self.interface1.load(&mut store, &_instance)?;
156             let interface2 = self.interface2.load(&mut store, &_instance)?;
157             let interface3 = self.interface3.load(&mut store, &_instance)?;
158             Ok(W {
159                 interface0,
160                 interface1,
161                 interface2,
162                 interface3,
163             })
164         }
165     }
166     impl W {
167         /// Convenience wrapper around [`WPre::new`] and
168         /// [`WPre::instantiate`].
instantiate<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<W>169         pub fn instantiate<_T>(
170             store: impl wasmtime::AsContextMut<Data = _T>,
171             component: &wasmtime::component::Component,
172             linker: &wasmtime::component::Linker<_T>,
173         ) -> wasmtime::Result<W> {
174             let pre = linker.instantiate_pre(component)?;
175             WPre::new(pre)?.instantiate(store)
176         }
177         /// Convenience wrapper around [`WIndices::new`] and
178         /// [`WIndices::load`].
new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<W>179         pub fn new(
180             mut store: impl wasmtime::AsContextMut,
181             instance: &wasmtime::component::Instance,
182         ) -> wasmtime::Result<W> {
183             let indices = WIndices::new(&instance.instance_pre(&store))?;
184             indices.load(&mut store, instance)
185         }
186         /// Convenience wrapper around [`WPre::new`] and
187         /// [`WPre::instantiate_async`].
instantiate_async<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<W> where _T: Send,188         pub async fn instantiate_async<_T>(
189             store: impl wasmtime::AsContextMut<Data = _T>,
190             component: &wasmtime::component::Component,
191             linker: &wasmtime::component::Linker<_T>,
192         ) -> wasmtime::Result<W>
193         where
194             _T: Send,
195         {
196             let pre = linker.instantiate_pre(component)?;
197             WPre::new(pre)?.instantiate_async(store).await
198         }
add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: foo::foo::transitive_import::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send, T: 'static + Send,199         pub fn add_to_linker<T, D>(
200             linker: &mut wasmtime::component::Linker<T>,
201             host_getter: fn(&mut T) -> D::Data<'_>,
202         ) -> wasmtime::Result<()>
203         where
204             D: foo::foo::transitive_import::HostWithStore + Send,
205             for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send,
206             T: 'static + Send,
207         {
208             foo::foo::transitive_import::add_to_linker::<T, D>(linker, host_getter)?;
209             Ok(())
210         }
foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest211         pub fn foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest {
212             &self.interface0
213         }
foo_foo_export_using_import( &self, ) -> &exports::foo::foo::export_using_import::Guest214         pub fn foo_foo_export_using_import(
215             &self,
216         ) -> &exports::foo::foo::export_using_import::Guest {
217             &self.interface1
218         }
foo_foo_export_using_export1( &self, ) -> &exports::foo::foo::export_using_export1::Guest219         pub fn foo_foo_export_using_export1(
220             &self,
221         ) -> &exports::foo::foo::export_using_export1::Guest {
222             &self.interface2
223         }
foo_foo_export_using_export2( &self, ) -> &exports::foo::foo::export_using_export2::Guest224         pub fn foo_foo_export_using_export2(
225             &self,
226         ) -> &exports::foo::foo::export_using_export2::Guest {
227             &self.interface3
228         }
229     }
230 };
231 pub mod foo {
232     pub mod foo {
233         #[allow(clippy::all)]
234         pub mod transitive_import {
235             #[allow(unused_imports)]
236             use wasmtime::component::__internal::Box;
237             pub enum Y {}
238             pub trait HostYWithStore: wasmtime::component::HasData {}
239             impl<_T: ?Sized> HostYWithStore for _T
240             where
241                 _T: wasmtime::component::HasData,
242             {}
243             pub trait HostY {
drop( &mut self, rep: wasmtime::component::Resource<Y>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send244                 fn drop(
245                     &mut self,
246                     rep: wasmtime::component::Resource<Y>,
247                 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send;
248             }
249             impl<_T: HostY + ?Sized + Send> HostY for &mut _T {
drop( &mut self, rep: wasmtime::component::Resource<Y>, ) -> wasmtime::Result<()>250                 async fn drop(
251                     &mut self,
252                     rep: wasmtime::component::Resource<Y>,
253                 ) -> wasmtime::Result<()> {
254                     HostY::drop(*self, rep).await
255                 }
256             }
257             pub trait HostWithStore: wasmtime::component::HasData + HostYWithStore + Send {}
258             impl<_T: ?Sized> HostWithStore for _T
259             where
260                 _T: wasmtime::component::HasData + HostYWithStore + Send,
261             {}
262             pub trait Host: HostY + Send {}
263             impl<_T: Host + ?Sized + Send> Host for &mut _T {}
add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: HostWithStore, for<'a> D::Data<'a>: Host, T: 'static + Send,264             pub fn add_to_linker<T, D>(
265                 linker: &mut wasmtime::component::Linker<T>,
266                 host_getter: fn(&mut T) -> D::Data<'_>,
267             ) -> wasmtime::Result<()>
268             where
269                 D: HostWithStore,
270                 for<'a> D::Data<'a>: Host,
271                 T: 'static + Send,
272             {
273                 let mut inst = linker.instance("foo:foo/transitive-import")?;
274                 inst.resource_async(
275                     "y",
276                     wasmtime::component::ResourceType::host::<Y>(),
277                     move |mut store, rep| {
278                         wasmtime::component::__internal::Box::new(async move {
279                             wasmtime::ToWasmtimeResult::to_wasmtime_result(
280                                 HostY::drop(
281                                         &mut host_getter(store.data_mut()),
282                                         wasmtime::component::Resource::new_own(rep),
283                                     )
284                                     .await,
285                             )
286                         })
287                     },
288                 )?;
289                 Ok(())
290             }
291         }
292     }
293 }
294 pub mod exports {
295     pub mod foo {
296         pub mod foo {
297             #[allow(clippy::all)]
298             pub mod simple_export {
299                 #[allow(unused_imports)]
300                 use wasmtime::component::__internal::Box;
301                 pub type A = wasmtime::component::ResourceAny;
302                 pub struct GuestA<'a> {
303                     funcs: &'a Guest,
304                 }
305                 #[derive(Clone)]
306                 pub struct Guest {
307                     constructor_a_constructor: wasmtime::component::Func,
308                     static_a_static_a: wasmtime::component::Func,
309                     method_a_method_a: wasmtime::component::Func,
310                 }
311                 #[derive(Clone)]
312                 pub struct GuestIndices {
313                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
314                     static_a_static_a: wasmtime::component::ComponentExportIndex,
315                     method_a_method_a: wasmtime::component::ComponentExportIndex,
316                 }
317                 impl GuestIndices {
318                     /// Constructor for [`GuestIndices`] which takes a
319                     /// [`Component`](wasmtime::component::Component) as input and can be executed
320                     /// before instantiation.
321                     ///
322                     /// This constructor can be used to front-load string lookups to find exports
323                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>324                     pub fn new<_T>(
325                         _instance_pre: &wasmtime::component::InstancePre<_T>,
326                     ) -> wasmtime::Result<GuestIndices> {
327                         let instance = _instance_pre
328                             .component()
329                             .get_export_index(None, "foo:foo/simple-export")
330                             .ok_or_else(|| {
331                                 wasmtime::format_err!(
332                                     "no exported instance named `foo:foo/simple-export`"
333                                 )
334                             })?;
335                         let mut lookup = move |name| {
336                             _instance_pre
337                                 .component()
338                                 .get_export_index(Some(&instance), name)
339                                 .ok_or_else(|| {
340                                     wasmtime::format_err!(
341                                         "instance export `foo:foo/simple-export` does \
342                   not have export `{name}`"
343                                     )
344                                 })
345                         };
346                         let _ = &mut lookup;
347                         let constructor_a_constructor = lookup("[constructor]a")?;
348                         let static_a_static_a = lookup("[static]a.static-a")?;
349                         let method_a_method_a = lookup("[method]a.method-a")?;
350                         Ok(GuestIndices {
351                             constructor_a_constructor,
352                             static_a_static_a,
353                             method_a_method_a,
354                         })
355                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>356                     pub fn load(
357                         &self,
358                         mut store: impl wasmtime::AsContextMut,
359                         instance: &wasmtime::component::Instance,
360                     ) -> wasmtime::Result<Guest> {
361                         let _instance = instance;
362                         let _instance_pre = _instance.instance_pre(&store);
363                         let _instance_type = _instance_pre.instance_type();
364                         let mut store = store.as_context_mut();
365                         let _ = &mut store;
366                         let constructor_a_constructor = *_instance
367                             .get_typed_func::<
368                                 (),
369                                 (wasmtime::component::ResourceAny,),
370                             >(&mut store, &self.constructor_a_constructor)?
371                             .func();
372                         let static_a_static_a = *_instance
373                             .get_typed_func::<
374                                 (),
375                                 (u32,),
376                             >(&mut store, &self.static_a_static_a)?
377                             .func();
378                         let method_a_method_a = *_instance
379                             .get_typed_func::<
380                                 (wasmtime::component::ResourceAny,),
381                                 (u32,),
382                             >(&mut store, &self.method_a_method_a)?
383                             .func();
384                         Ok(Guest {
385                             constructor_a_constructor,
386                             static_a_static_a,
387                             method_a_method_a,
388                         })
389                     }
390                 }
391                 impl Guest {
a(&self) -> GuestA<'_>392                     pub fn a(&self) -> GuestA<'_> {
393                         GuestA { funcs: self }
394                     }
395                 }
396                 impl GuestA<'_> {
call_constructor<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<wasmtime::component::ResourceAny> where <S as wasmtime::AsContext>::Data: Send,397                     pub async fn call_constructor<S: wasmtime::AsContextMut>(
398                         &self,
399                         mut store: S,
400                     ) -> wasmtime::Result<wasmtime::component::ResourceAny>
401                     where
402                         <S as wasmtime::AsContext>::Data: Send,
403                     {
404                         let callee = unsafe {
405                             wasmtime::component::TypedFunc::<
406                                 (),
407                                 (wasmtime::component::ResourceAny,),
408                             >::new_unchecked(self.funcs.constructor_a_constructor)
409                         };
410                         let (ret0,) = callee
411                             .call_async(store.as_context_mut(), ())
412                             .await?;
413                         Ok(ret0)
414                     }
call_static_a<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<u32> where <S as wasmtime::AsContext>::Data: Send,415                     pub async fn call_static_a<S: wasmtime::AsContextMut>(
416                         &self,
417                         mut store: S,
418                     ) -> wasmtime::Result<u32>
419                     where
420                         <S as wasmtime::AsContext>::Data: Send,
421                     {
422                         let callee = unsafe {
423                             wasmtime::component::TypedFunc::<
424                                 (),
425                                 (u32,),
426                             >::new_unchecked(self.funcs.static_a_static_a)
427                         };
428                         let (ret0,) = callee
429                             .call_async(store.as_context_mut(), ())
430                             .await?;
431                         Ok(ret0)
432                     }
call_method_a<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::ResourceAny, ) -> wasmtime::Result<u32> where <S as wasmtime::AsContext>::Data: Send,433                     pub async fn call_method_a<S: wasmtime::AsContextMut>(
434                         &self,
435                         mut store: S,
436                         arg0: wasmtime::component::ResourceAny,
437                     ) -> wasmtime::Result<u32>
438                     where
439                         <S as wasmtime::AsContext>::Data: Send,
440                     {
441                         let callee = unsafe {
442                             wasmtime::component::TypedFunc::<
443                                 (wasmtime::component::ResourceAny,),
444                                 (u32,),
445                             >::new_unchecked(self.funcs.method_a_method_a)
446                         };
447                         let (ret0,) = callee
448                             .call_async(store.as_context_mut(), (arg0,))
449                             .await?;
450                         Ok(ret0)
451                     }
452                 }
453             }
454             #[allow(clippy::all)]
455             pub mod export_using_import {
456                 #[allow(unused_imports)]
457                 use wasmtime::component::__internal::Box;
458                 pub type Y = super::super::super::super::foo::foo::transitive_import::Y;
459                 pub type A = wasmtime::component::ResourceAny;
460                 pub struct GuestA<'a> {
461                     funcs: &'a Guest,
462                 }
463                 #[derive(Clone)]
464                 pub struct Guest {
465                     constructor_a_constructor: wasmtime::component::Func,
466                     static_a_static_a: wasmtime::component::Func,
467                     method_a_method_a: wasmtime::component::Func,
468                 }
469                 #[derive(Clone)]
470                 pub struct GuestIndices {
471                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
472                     static_a_static_a: wasmtime::component::ComponentExportIndex,
473                     method_a_method_a: wasmtime::component::ComponentExportIndex,
474                 }
475                 impl GuestIndices {
476                     /// Constructor for [`GuestIndices`] which takes a
477                     /// [`Component`](wasmtime::component::Component) as input and can be executed
478                     /// before instantiation.
479                     ///
480                     /// This constructor can be used to front-load string lookups to find exports
481                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>482                     pub fn new<_T>(
483                         _instance_pre: &wasmtime::component::InstancePre<_T>,
484                     ) -> wasmtime::Result<GuestIndices> {
485                         let instance = _instance_pre
486                             .component()
487                             .get_export_index(None, "foo:foo/export-using-import")
488                             .ok_or_else(|| {
489                                 wasmtime::format_err!(
490                                     "no exported instance named `foo:foo/export-using-import`"
491                                 )
492                             })?;
493                         let mut lookup = move |name| {
494                             _instance_pre
495                                 .component()
496                                 .get_export_index(Some(&instance), name)
497                                 .ok_or_else(|| {
498                                     wasmtime::format_err!(
499                                         "instance export `foo:foo/export-using-import` does \
500                   not have export `{name}`"
501                                     )
502                                 })
503                         };
504                         let _ = &mut lookup;
505                         let constructor_a_constructor = lookup("[constructor]a")?;
506                         let static_a_static_a = lookup("[static]a.static-a")?;
507                         let method_a_method_a = lookup("[method]a.method-a")?;
508                         Ok(GuestIndices {
509                             constructor_a_constructor,
510                             static_a_static_a,
511                             method_a_method_a,
512                         })
513                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>514                     pub fn load(
515                         &self,
516                         mut store: impl wasmtime::AsContextMut,
517                         instance: &wasmtime::component::Instance,
518                     ) -> wasmtime::Result<Guest> {
519                         let _instance = instance;
520                         let _instance_pre = _instance.instance_pre(&store);
521                         let _instance_type = _instance_pre.instance_type();
522                         let mut store = store.as_context_mut();
523                         let _ = &mut store;
524                         let constructor_a_constructor = *_instance
525                             .get_typed_func::<
526                                 (wasmtime::component::Resource<Y>,),
527                                 (wasmtime::component::ResourceAny,),
528                             >(&mut store, &self.constructor_a_constructor)?
529                             .func();
530                         let static_a_static_a = *_instance
531                             .get_typed_func::<
532                                 (),
533                                 (wasmtime::component::Resource<Y>,),
534                             >(&mut store, &self.static_a_static_a)?
535                             .func();
536                         let method_a_method_a = *_instance
537                             .get_typed_func::<
538                                 (
539                                     wasmtime::component::ResourceAny,
540                                     wasmtime::component::Resource<Y>,
541                                 ),
542                                 (wasmtime::component::Resource<Y>,),
543                             >(&mut store, &self.method_a_method_a)?
544                             .func();
545                         Ok(Guest {
546                             constructor_a_constructor,
547                             static_a_static_a,
548                             method_a_method_a,
549                         })
550                     }
551                 }
552                 impl Guest {
a(&self) -> GuestA<'_>553                     pub fn a(&self) -> GuestA<'_> {
554                         GuestA { funcs: self }
555                     }
556                 }
557                 impl GuestA<'_> {
call_constructor<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::Resource<Y>, ) -> wasmtime::Result<wasmtime::component::ResourceAny> where <S as wasmtime::AsContext>::Data: Send,558                     pub async fn call_constructor<S: wasmtime::AsContextMut>(
559                         &self,
560                         mut store: S,
561                         arg0: wasmtime::component::Resource<Y>,
562                     ) -> wasmtime::Result<wasmtime::component::ResourceAny>
563                     where
564                         <S as wasmtime::AsContext>::Data: Send,
565                     {
566                         let callee = unsafe {
567                             wasmtime::component::TypedFunc::<
568                                 (wasmtime::component::Resource<Y>,),
569                                 (wasmtime::component::ResourceAny,),
570                             >::new_unchecked(self.funcs.constructor_a_constructor)
571                         };
572                         let (ret0,) = callee
573                             .call_async(store.as_context_mut(), (arg0,))
574                             .await?;
575                         Ok(ret0)
576                     }
call_static_a<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<wasmtime::component::Resource<Y>> where <S as wasmtime::AsContext>::Data: Send,577                     pub async fn call_static_a<S: wasmtime::AsContextMut>(
578                         &self,
579                         mut store: S,
580                     ) -> wasmtime::Result<wasmtime::component::Resource<Y>>
581                     where
582                         <S as wasmtime::AsContext>::Data: Send,
583                     {
584                         let callee = unsafe {
585                             wasmtime::component::TypedFunc::<
586                                 (),
587                                 (wasmtime::component::Resource<Y>,),
588                             >::new_unchecked(self.funcs.static_a_static_a)
589                         };
590                         let (ret0,) = callee
591                             .call_async(store.as_context_mut(), ())
592                             .await?;
593                         Ok(ret0)
594                     }
call_method_a<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::ResourceAny, arg1: wasmtime::component::Resource<Y>, ) -> wasmtime::Result<wasmtime::component::Resource<Y>> where <S as wasmtime::AsContext>::Data: Send,595                     pub async fn call_method_a<S: wasmtime::AsContextMut>(
596                         &self,
597                         mut store: S,
598                         arg0: wasmtime::component::ResourceAny,
599                         arg1: wasmtime::component::Resource<Y>,
600                     ) -> wasmtime::Result<wasmtime::component::Resource<Y>>
601                     where
602                         <S as wasmtime::AsContext>::Data: Send,
603                     {
604                         let callee = unsafe {
605                             wasmtime::component::TypedFunc::<
606                                 (
607                                     wasmtime::component::ResourceAny,
608                                     wasmtime::component::Resource<Y>,
609                                 ),
610                                 (wasmtime::component::Resource<Y>,),
611                             >::new_unchecked(self.funcs.method_a_method_a)
612                         };
613                         let (ret0,) = callee
614                             .call_async(store.as_context_mut(), (arg0, arg1))
615                             .await?;
616                         Ok(ret0)
617                     }
618                 }
619             }
620             #[allow(clippy::all)]
621             pub mod export_using_export1 {
622                 #[allow(unused_imports)]
623                 use wasmtime::component::__internal::Box;
624                 pub type A = wasmtime::component::ResourceAny;
625                 pub struct GuestA<'a> {
626                     funcs: &'a Guest,
627                 }
628                 #[derive(Clone)]
629                 pub struct Guest {
630                     constructor_a_constructor: wasmtime::component::Func,
631                 }
632                 #[derive(Clone)]
633                 pub struct GuestIndices {
634                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
635                 }
636                 impl GuestIndices {
637                     /// Constructor for [`GuestIndices`] which takes a
638                     /// [`Component`](wasmtime::component::Component) as input and can be executed
639                     /// before instantiation.
640                     ///
641                     /// This constructor can be used to front-load string lookups to find exports
642                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>643                     pub fn new<_T>(
644                         _instance_pre: &wasmtime::component::InstancePre<_T>,
645                     ) -> wasmtime::Result<GuestIndices> {
646                         let instance = _instance_pre
647                             .component()
648                             .get_export_index(None, "foo:foo/export-using-export1")
649                             .ok_or_else(|| {
650                                 wasmtime::format_err!(
651                                     "no exported instance named `foo:foo/export-using-export1`"
652                                 )
653                             })?;
654                         let mut lookup = move |name| {
655                             _instance_pre
656                                 .component()
657                                 .get_export_index(Some(&instance), name)
658                                 .ok_or_else(|| {
659                                     wasmtime::format_err!(
660                                         "instance export `foo:foo/export-using-export1` does \
661                   not have export `{name}`"
662                                     )
663                                 })
664                         };
665                         let _ = &mut lookup;
666                         let constructor_a_constructor = lookup("[constructor]a")?;
667                         Ok(GuestIndices {
668                             constructor_a_constructor,
669                         })
670                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>671                     pub fn load(
672                         &self,
673                         mut store: impl wasmtime::AsContextMut,
674                         instance: &wasmtime::component::Instance,
675                     ) -> wasmtime::Result<Guest> {
676                         let _instance = instance;
677                         let _instance_pre = _instance.instance_pre(&store);
678                         let _instance_type = _instance_pre.instance_type();
679                         let mut store = store.as_context_mut();
680                         let _ = &mut store;
681                         let constructor_a_constructor = *_instance
682                             .get_typed_func::<
683                                 (),
684                                 (wasmtime::component::ResourceAny,),
685                             >(&mut store, &self.constructor_a_constructor)?
686                             .func();
687                         Ok(Guest { constructor_a_constructor })
688                     }
689                 }
690                 impl Guest {
a(&self) -> GuestA<'_>691                     pub fn a(&self) -> GuestA<'_> {
692                         GuestA { funcs: self }
693                     }
694                 }
695                 impl GuestA<'_> {
call_constructor<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<wasmtime::component::ResourceAny> where <S as wasmtime::AsContext>::Data: Send,696                     pub async fn call_constructor<S: wasmtime::AsContextMut>(
697                         &self,
698                         mut store: S,
699                     ) -> wasmtime::Result<wasmtime::component::ResourceAny>
700                     where
701                         <S as wasmtime::AsContext>::Data: Send,
702                     {
703                         let callee = unsafe {
704                             wasmtime::component::TypedFunc::<
705                                 (),
706                                 (wasmtime::component::ResourceAny,),
707                             >::new_unchecked(self.funcs.constructor_a_constructor)
708                         };
709                         let (ret0,) = callee
710                             .call_async(store.as_context_mut(), ())
711                             .await?;
712                         Ok(ret0)
713                     }
714                 }
715             }
716             #[allow(clippy::all)]
717             pub mod export_using_export2 {
718                 #[allow(unused_imports)]
719                 use wasmtime::component::__internal::Box;
720                 pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A;
721                 pub type B = wasmtime::component::ResourceAny;
722                 pub struct GuestB<'a> {
723                     funcs: &'a Guest,
724                 }
725                 #[derive(Clone)]
726                 pub struct Guest {
727                     constructor_b_constructor: wasmtime::component::Func,
728                 }
729                 #[derive(Clone)]
730                 pub struct GuestIndices {
731                     constructor_b_constructor: wasmtime::component::ComponentExportIndex,
732                 }
733                 impl GuestIndices {
734                     /// Constructor for [`GuestIndices`] which takes a
735                     /// [`Component`](wasmtime::component::Component) as input and can be executed
736                     /// before instantiation.
737                     ///
738                     /// This constructor can be used to front-load string lookups to find exports
739                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>740                     pub fn new<_T>(
741                         _instance_pre: &wasmtime::component::InstancePre<_T>,
742                     ) -> wasmtime::Result<GuestIndices> {
743                         let instance = _instance_pre
744                             .component()
745                             .get_export_index(None, "foo:foo/export-using-export2")
746                             .ok_or_else(|| {
747                                 wasmtime::format_err!(
748                                     "no exported instance named `foo:foo/export-using-export2`"
749                                 )
750                             })?;
751                         let mut lookup = move |name| {
752                             _instance_pre
753                                 .component()
754                                 .get_export_index(Some(&instance), name)
755                                 .ok_or_else(|| {
756                                     wasmtime::format_err!(
757                                         "instance export `foo:foo/export-using-export2` does \
758                   not have export `{name}`"
759                                     )
760                                 })
761                         };
762                         let _ = &mut lookup;
763                         let constructor_b_constructor = lookup("[constructor]b")?;
764                         Ok(GuestIndices {
765                             constructor_b_constructor,
766                         })
767                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>768                     pub fn load(
769                         &self,
770                         mut store: impl wasmtime::AsContextMut,
771                         instance: &wasmtime::component::Instance,
772                     ) -> wasmtime::Result<Guest> {
773                         let _instance = instance;
774                         let _instance_pre = _instance.instance_pre(&store);
775                         let _instance_type = _instance_pre.instance_type();
776                         let mut store = store.as_context_mut();
777                         let _ = &mut store;
778                         let constructor_b_constructor = *_instance
779                             .get_typed_func::<
780                                 (wasmtime::component::ResourceAny,),
781                                 (wasmtime::component::ResourceAny,),
782                             >(&mut store, &self.constructor_b_constructor)?
783                             .func();
784                         Ok(Guest { constructor_b_constructor })
785                     }
786                 }
787                 impl Guest {
b(&self) -> GuestB<'_>788                     pub fn b(&self) -> GuestB<'_> {
789                         GuestB { funcs: self }
790                     }
791                 }
792                 impl GuestB<'_> {
call_constructor<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::ResourceAny, ) -> wasmtime::Result<wasmtime::component::ResourceAny> where <S as wasmtime::AsContext>::Data: Send,793                     pub async fn call_constructor<S: wasmtime::AsContextMut>(
794                         &self,
795                         mut store: S,
796                         arg0: wasmtime::component::ResourceAny,
797                     ) -> wasmtime::Result<wasmtime::component::ResourceAny>
798                     where
799                         <S as wasmtime::AsContext>::Data: Send,
800                     {
801                         let callee = unsafe {
802                             wasmtime::component::TypedFunc::<
803                                 (wasmtime::component::ResourceAny,),
804                                 (wasmtime::component::ResourceAny,),
805                             >::new_unchecked(self.funcs.constructor_b_constructor)
806                         };
807                         let (ret0,) = callee
808                             .call_async(store.as_context_mut(), (arg0,))
809                             .await?;
810                         Ok(ret0)
811                     }
812                 }
813             }
814         }
815     }
816 }
817