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