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