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> {
14     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.
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     }
33     pub fn engine(&self) -> &wasmtime::Engine {
34         self.instance_pre.engine()
35     }
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.
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`.
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.
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.
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`].
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`].
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`].
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         }
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,
205             for<'a> D::Data<'a>: foo::foo::transitive_import::Host,
206             T: 'static,
207         {
208             foo::foo::transitive_import::add_to_linker::<T, D>(linker, host_getter)?;
209             Ok(())
210         }
211         pub fn foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest {
212             &self.interface0
213         }
214         pub fn foo_foo_export_using_import(
215             &self,
216         ) -> &exports::foo::foo::export_using_import::Guest {
217             &self.interface1
218         }
219         pub fn foo_foo_export_using_export1(
220             &self,
221         ) -> &exports::foo::foo::export_using_export1::Guest {
222             &self.interface2
223         }
224         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 {
244                 fn drop(
245                     &mut self,
246                     rep: wasmtime::component::Resource<Y>,
247                 ) -> wasmtime::Result<()>;
248             }
249             impl<_T: HostY + ?Sized> HostY for &mut _T {
250                 fn drop(
251                     &mut self,
252                     rep: wasmtime::component::Resource<Y>,
253                 ) -> wasmtime::Result<()> {
254                     HostY::drop(*self, rep)
255                 }
256             }
257             pub trait HostWithStore: wasmtime::component::HasData + HostYWithStore {}
258             impl<_T: ?Sized> HostWithStore for _T
259             where
260                 _T: wasmtime::component::HasData + HostYWithStore,
261             {}
262             pub trait Host: HostY {}
263             impl<_T: Host + ?Sized> Host for &mut _T {}
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,
272             {
273                 let mut inst = linker.instance("foo:foo/transitive-import")?;
274                 inst.resource(
275                     "y",
276                     wasmtime::component::ResourceType::host::<Y>(),
277                     move |mut store, rep| -> wasmtime::Result<()> {
278                         let resource = wasmtime::component::Resource::new_own(rep);
279                         HostY::drop(&mut host_getter(store.data_mut()), resource)
280                     },
281                 )?;
282                 Ok(())
283             }
284         }
285     }
286 }
287 pub mod exports {
288     pub mod foo {
289         pub mod foo {
290             #[allow(clippy::all)]
291             pub mod simple_export {
292                 #[allow(unused_imports)]
293                 use wasmtime::component::__internal::Box;
294                 pub type A = wasmtime::component::ResourceAny;
295                 pub struct GuestA<'a> {
296                     funcs: &'a Guest,
297                 }
298                 #[derive(Clone)]
299                 pub struct Guest {
300                     constructor_a_constructor: wasmtime::component::Func,
301                     static_a_static_a: wasmtime::component::Func,
302                     method_a_method_a: wasmtime::component::Func,
303                 }
304                 #[derive(Clone)]
305                 pub struct GuestIndices {
306                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
307                     static_a_static_a: wasmtime::component::ComponentExportIndex,
308                     method_a_method_a: wasmtime::component::ComponentExportIndex,
309                 }
310                 impl GuestIndices {
311                     /// Constructor for [`GuestIndices`] which takes a
312                     /// [`Component`](wasmtime::component::Component) as input and can be executed
313                     /// before instantiation.
314                     ///
315                     /// This constructor can be used to front-load string lookups to find exports
316                     /// within a component.
317                     pub fn new<_T>(
318                         _instance_pre: &wasmtime::component::InstancePre<_T>,
319                     ) -> wasmtime::Result<GuestIndices> {
320                         let instance = _instance_pre
321                             .component()
322                             .get_export_index(None, "foo:foo/simple-export")
323                             .ok_or_else(|| {
324                                 wasmtime::format_err!(
325                                     "no exported instance named `foo:foo/simple-export`"
326                                 )
327                             })?;
328                         let mut lookup = move |name| {
329                             _instance_pre
330                                 .component()
331                                 .get_export_index(Some(&instance), name)
332                                 .ok_or_else(|| {
333                                     wasmtime::format_err!(
334                                         "instance export `foo:foo/simple-export` does \
335                   not have export `{name}`"
336                                     )
337                                 })
338                         };
339                         let _ = &mut lookup;
340                         let constructor_a_constructor = lookup("[constructor]a")?;
341                         let static_a_static_a = lookup("[static]a.static-a")?;
342                         let method_a_method_a = lookup("[method]a.method-a")?;
343                         Ok(GuestIndices {
344                             constructor_a_constructor,
345                             static_a_static_a,
346                             method_a_method_a,
347                         })
348                     }
349                     pub fn load(
350                         &self,
351                         mut store: impl wasmtime::AsContextMut,
352                         instance: &wasmtime::component::Instance,
353                     ) -> wasmtime::Result<Guest> {
354                         let _instance = instance;
355                         let _instance_pre = _instance.instance_pre(&store);
356                         let _instance_type = _instance_pre.instance_type();
357                         let mut store = store.as_context_mut();
358                         let _ = &mut store;
359                         let constructor_a_constructor = *_instance
360                             .get_typed_func::<
361                                 (),
362                                 (wasmtime::component::ResourceAny,),
363                             >(&mut store, &self.constructor_a_constructor)?
364                             .func();
365                         let static_a_static_a = *_instance
366                             .get_typed_func::<
367                                 (),
368                                 (u32,),
369                             >(&mut store, &self.static_a_static_a)?
370                             .func();
371                         let method_a_method_a = *_instance
372                             .get_typed_func::<
373                                 (wasmtime::component::ResourceAny,),
374                                 (u32,),
375                             >(&mut store, &self.method_a_method_a)?
376                             .func();
377                         Ok(Guest {
378                             constructor_a_constructor,
379                             static_a_static_a,
380                             method_a_method_a,
381                         })
382                     }
383                 }
384                 impl Guest {
385                     pub fn a(&self) -> GuestA<'_> {
386                         GuestA { funcs: self }
387                     }
388                 }
389                 impl GuestA<'_> {
390                     pub fn call_constructor<S: wasmtime::AsContextMut>(
391                         &self,
392                         mut store: S,
393                     ) -> wasmtime::Result<wasmtime::component::ResourceAny> {
394                         let callee = unsafe {
395                             wasmtime::component::TypedFunc::<
396                                 (),
397                                 (wasmtime::component::ResourceAny,),
398                             >::new_unchecked(self.funcs.constructor_a_constructor)
399                         };
400                         let (ret0,) = callee.call(store.as_context_mut(), ())?;
401                         Ok(ret0)
402                     }
403                     pub fn call_static_a<S: wasmtime::AsContextMut>(
404                         &self,
405                         mut store: S,
406                     ) -> wasmtime::Result<u32> {
407                         let callee = unsafe {
408                             wasmtime::component::TypedFunc::<
409                                 (),
410                                 (u32,),
411                             >::new_unchecked(self.funcs.static_a_static_a)
412                         };
413                         let (ret0,) = callee.call(store.as_context_mut(), ())?;
414                         Ok(ret0)
415                     }
416                     pub fn call_method_a<S: wasmtime::AsContextMut>(
417                         &self,
418                         mut store: S,
419                         arg0: wasmtime::component::ResourceAny,
420                     ) -> wasmtime::Result<u32> {
421                         let callee = unsafe {
422                             wasmtime::component::TypedFunc::<
423                                 (wasmtime::component::ResourceAny,),
424                                 (u32,),
425                             >::new_unchecked(self.funcs.method_a_method_a)
426                         };
427                         let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
428                         Ok(ret0)
429                     }
430                 }
431             }
432             #[allow(clippy::all)]
433             pub mod export_using_import {
434                 #[allow(unused_imports)]
435                 use wasmtime::component::__internal::Box;
436                 pub type Y = super::super::super::super::foo::foo::transitive_import::Y;
437                 pub type A = wasmtime::component::ResourceAny;
438                 pub struct GuestA<'a> {
439                     funcs: &'a Guest,
440                 }
441                 #[derive(Clone)]
442                 pub struct Guest {
443                     constructor_a_constructor: wasmtime::component::Func,
444                     static_a_static_a: wasmtime::component::Func,
445                     method_a_method_a: wasmtime::component::Func,
446                 }
447                 #[derive(Clone)]
448                 pub struct GuestIndices {
449                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
450                     static_a_static_a: wasmtime::component::ComponentExportIndex,
451                     method_a_method_a: wasmtime::component::ComponentExportIndex,
452                 }
453                 impl GuestIndices {
454                     /// Constructor for [`GuestIndices`] which takes a
455                     /// [`Component`](wasmtime::component::Component) as input and can be executed
456                     /// before instantiation.
457                     ///
458                     /// This constructor can be used to front-load string lookups to find exports
459                     /// within a component.
460                     pub fn new<_T>(
461                         _instance_pre: &wasmtime::component::InstancePre<_T>,
462                     ) -> wasmtime::Result<GuestIndices> {
463                         let instance = _instance_pre
464                             .component()
465                             .get_export_index(None, "foo:foo/export-using-import")
466                             .ok_or_else(|| {
467                                 wasmtime::format_err!(
468                                     "no exported instance named `foo:foo/export-using-import`"
469                                 )
470                             })?;
471                         let mut lookup = move |name| {
472                             _instance_pre
473                                 .component()
474                                 .get_export_index(Some(&instance), name)
475                                 .ok_or_else(|| {
476                                     wasmtime::format_err!(
477                                         "instance export `foo:foo/export-using-import` does \
478                   not have export `{name}`"
479                                     )
480                                 })
481                         };
482                         let _ = &mut lookup;
483                         let constructor_a_constructor = lookup("[constructor]a")?;
484                         let static_a_static_a = lookup("[static]a.static-a")?;
485                         let method_a_method_a = lookup("[method]a.method-a")?;
486                         Ok(GuestIndices {
487                             constructor_a_constructor,
488                             static_a_static_a,
489                             method_a_method_a,
490                         })
491                     }
492                     pub fn load(
493                         &self,
494                         mut store: impl wasmtime::AsContextMut,
495                         instance: &wasmtime::component::Instance,
496                     ) -> wasmtime::Result<Guest> {
497                         let _instance = instance;
498                         let _instance_pre = _instance.instance_pre(&store);
499                         let _instance_type = _instance_pre.instance_type();
500                         let mut store = store.as_context_mut();
501                         let _ = &mut store;
502                         let constructor_a_constructor = *_instance
503                             .get_typed_func::<
504                                 (wasmtime::component::Resource<Y>,),
505                                 (wasmtime::component::ResourceAny,),
506                             >(&mut store, &self.constructor_a_constructor)?
507                             .func();
508                         let static_a_static_a = *_instance
509                             .get_typed_func::<
510                                 (),
511                                 (wasmtime::component::Resource<Y>,),
512                             >(&mut store, &self.static_a_static_a)?
513                             .func();
514                         let method_a_method_a = *_instance
515                             .get_typed_func::<
516                                 (
517                                     wasmtime::component::ResourceAny,
518                                     wasmtime::component::Resource<Y>,
519                                 ),
520                                 (wasmtime::component::Resource<Y>,),
521                             >(&mut store, &self.method_a_method_a)?
522                             .func();
523                         Ok(Guest {
524                             constructor_a_constructor,
525                             static_a_static_a,
526                             method_a_method_a,
527                         })
528                     }
529                 }
530                 impl Guest {
531                     pub fn a(&self) -> GuestA<'_> {
532                         GuestA { funcs: self }
533                     }
534                 }
535                 impl GuestA<'_> {
536                     pub fn call_constructor<S: wasmtime::AsContextMut>(
537                         &self,
538                         mut store: S,
539                         arg0: wasmtime::component::Resource<Y>,
540                     ) -> wasmtime::Result<wasmtime::component::ResourceAny> {
541                         let callee = unsafe {
542                             wasmtime::component::TypedFunc::<
543                                 (wasmtime::component::Resource<Y>,),
544                                 (wasmtime::component::ResourceAny,),
545                             >::new_unchecked(self.funcs.constructor_a_constructor)
546                         };
547                         let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
548                         Ok(ret0)
549                     }
550                     pub fn call_static_a<S: wasmtime::AsContextMut>(
551                         &self,
552                         mut store: S,
553                     ) -> wasmtime::Result<wasmtime::component::Resource<Y>> {
554                         let callee = unsafe {
555                             wasmtime::component::TypedFunc::<
556                                 (),
557                                 (wasmtime::component::Resource<Y>,),
558                             >::new_unchecked(self.funcs.static_a_static_a)
559                         };
560                         let (ret0,) = callee.call(store.as_context_mut(), ())?;
561                         Ok(ret0)
562                     }
563                     pub fn call_method_a<S: wasmtime::AsContextMut>(
564                         &self,
565                         mut store: S,
566                         arg0: wasmtime::component::ResourceAny,
567                         arg1: wasmtime::component::Resource<Y>,
568                     ) -> wasmtime::Result<wasmtime::component::Resource<Y>> {
569                         let callee = unsafe {
570                             wasmtime::component::TypedFunc::<
571                                 (
572                                     wasmtime::component::ResourceAny,
573                                     wasmtime::component::Resource<Y>,
574                                 ),
575                                 (wasmtime::component::Resource<Y>,),
576                             >::new_unchecked(self.funcs.method_a_method_a)
577                         };
578                         let (ret0,) = callee.call(store.as_context_mut(), (arg0, arg1))?;
579                         Ok(ret0)
580                     }
581                 }
582             }
583             #[allow(clippy::all)]
584             pub mod export_using_export1 {
585                 #[allow(unused_imports)]
586                 use wasmtime::component::__internal::Box;
587                 pub type A = wasmtime::component::ResourceAny;
588                 pub struct GuestA<'a> {
589                     funcs: &'a Guest,
590                 }
591                 #[derive(Clone)]
592                 pub struct Guest {
593                     constructor_a_constructor: wasmtime::component::Func,
594                 }
595                 #[derive(Clone)]
596                 pub struct GuestIndices {
597                     constructor_a_constructor: wasmtime::component::ComponentExportIndex,
598                 }
599                 impl GuestIndices {
600                     /// Constructor for [`GuestIndices`] which takes a
601                     /// [`Component`](wasmtime::component::Component) as input and can be executed
602                     /// before instantiation.
603                     ///
604                     /// This constructor can be used to front-load string lookups to find exports
605                     /// within a component.
606                     pub fn new<_T>(
607                         _instance_pre: &wasmtime::component::InstancePre<_T>,
608                     ) -> wasmtime::Result<GuestIndices> {
609                         let instance = _instance_pre
610                             .component()
611                             .get_export_index(None, "foo:foo/export-using-export1")
612                             .ok_or_else(|| {
613                                 wasmtime::format_err!(
614                                     "no exported instance named `foo:foo/export-using-export1`"
615                                 )
616                             })?;
617                         let mut lookup = move |name| {
618                             _instance_pre
619                                 .component()
620                                 .get_export_index(Some(&instance), name)
621                                 .ok_or_else(|| {
622                                     wasmtime::format_err!(
623                                         "instance export `foo:foo/export-using-export1` does \
624                   not have export `{name}`"
625                                     )
626                                 })
627                         };
628                         let _ = &mut lookup;
629                         let constructor_a_constructor = lookup("[constructor]a")?;
630                         Ok(GuestIndices {
631                             constructor_a_constructor,
632                         })
633                     }
634                     pub fn load(
635                         &self,
636                         mut store: impl wasmtime::AsContextMut,
637                         instance: &wasmtime::component::Instance,
638                     ) -> wasmtime::Result<Guest> {
639                         let _instance = instance;
640                         let _instance_pre = _instance.instance_pre(&store);
641                         let _instance_type = _instance_pre.instance_type();
642                         let mut store = store.as_context_mut();
643                         let _ = &mut store;
644                         let constructor_a_constructor = *_instance
645                             .get_typed_func::<
646                                 (),
647                                 (wasmtime::component::ResourceAny,),
648                             >(&mut store, &self.constructor_a_constructor)?
649                             .func();
650                         Ok(Guest { constructor_a_constructor })
651                     }
652                 }
653                 impl Guest {
654                     pub fn a(&self) -> GuestA<'_> {
655                         GuestA { funcs: self }
656                     }
657                 }
658                 impl GuestA<'_> {
659                     pub fn call_constructor<S: wasmtime::AsContextMut>(
660                         &self,
661                         mut store: S,
662                     ) -> wasmtime::Result<wasmtime::component::ResourceAny> {
663                         let callee = unsafe {
664                             wasmtime::component::TypedFunc::<
665                                 (),
666                                 (wasmtime::component::ResourceAny,),
667                             >::new_unchecked(self.funcs.constructor_a_constructor)
668                         };
669                         let (ret0,) = callee.call(store.as_context_mut(), ())?;
670                         Ok(ret0)
671                     }
672                 }
673             }
674             #[allow(clippy::all)]
675             pub mod export_using_export2 {
676                 #[allow(unused_imports)]
677                 use wasmtime::component::__internal::Box;
678                 pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A;
679                 pub type B = wasmtime::component::ResourceAny;
680                 pub struct GuestB<'a> {
681                     funcs: &'a Guest,
682                 }
683                 #[derive(Clone)]
684                 pub struct Guest {
685                     constructor_b_constructor: wasmtime::component::Func,
686                 }
687                 #[derive(Clone)]
688                 pub struct GuestIndices {
689                     constructor_b_constructor: wasmtime::component::ComponentExportIndex,
690                 }
691                 impl GuestIndices {
692                     /// Constructor for [`GuestIndices`] which takes a
693                     /// [`Component`](wasmtime::component::Component) as input and can be executed
694                     /// before instantiation.
695                     ///
696                     /// This constructor can be used to front-load string lookups to find exports
697                     /// within a component.
698                     pub fn new<_T>(
699                         _instance_pre: &wasmtime::component::InstancePre<_T>,
700                     ) -> wasmtime::Result<GuestIndices> {
701                         let instance = _instance_pre
702                             .component()
703                             .get_export_index(None, "foo:foo/export-using-export2")
704                             .ok_or_else(|| {
705                                 wasmtime::format_err!(
706                                     "no exported instance named `foo:foo/export-using-export2`"
707                                 )
708                             })?;
709                         let mut lookup = move |name| {
710                             _instance_pre
711                                 .component()
712                                 .get_export_index(Some(&instance), name)
713                                 .ok_or_else(|| {
714                                     wasmtime::format_err!(
715                                         "instance export `foo:foo/export-using-export2` does \
716                   not have export `{name}`"
717                                     )
718                                 })
719                         };
720                         let _ = &mut lookup;
721                         let constructor_b_constructor = lookup("[constructor]b")?;
722                         Ok(GuestIndices {
723                             constructor_b_constructor,
724                         })
725                     }
726                     pub fn load(
727                         &self,
728                         mut store: impl wasmtime::AsContextMut,
729                         instance: &wasmtime::component::Instance,
730                     ) -> wasmtime::Result<Guest> {
731                         let _instance = instance;
732                         let _instance_pre = _instance.instance_pre(&store);
733                         let _instance_type = _instance_pre.instance_type();
734                         let mut store = store.as_context_mut();
735                         let _ = &mut store;
736                         let constructor_b_constructor = *_instance
737                             .get_typed_func::<
738                                 (wasmtime::component::ResourceAny,),
739                                 (wasmtime::component::ResourceAny,),
740                             >(&mut store, &self.constructor_b_constructor)?
741                             .func();
742                         Ok(Guest { constructor_b_constructor })
743                     }
744                 }
745                 impl Guest {
746                     pub fn b(&self) -> GuestB<'_> {
747                         GuestB { funcs: self }
748                     }
749                 }
750                 impl GuestB<'_> {
751                     pub fn call_constructor<S: wasmtime::AsContextMut>(
752                         &self,
753                         mut store: S,
754                         arg0: wasmtime::component::ResourceAny,
755                     ) -> wasmtime::Result<wasmtime::component::ResourceAny> {
756                         let callee = unsafe {
757                             wasmtime::component::TypedFunc::<
758                                 (wasmtime::component::ResourceAny,),
759                                 (wasmtime::component::ResourceAny,),
760                             >::new_unchecked(self.funcs.constructor_b_constructor)
761                         };
762                         let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
763                         Ok(ret0)
764                     }
765                 }
766             }
767         }
768     }
769 }
770