1 pub enum WorldResource {}
2 pub trait HostWorldResourceWithStore: wasmtime::component::HasData {}
3 impl<_T: ?Sized> HostWorldResourceWithStore for _T
4 where
5     _T: wasmtime::component::HasData,
6 {}
7 pub trait HostWorldResource {
new(&mut self) -> wasmtime::component::Resource<WorldResource>8     fn new(&mut self) -> wasmtime::component::Resource<WorldResource>;
foo(&mut self, self_: wasmtime::component::Resource<WorldResource>) -> ()9     fn foo(&mut self, self_: wasmtime::component::Resource<WorldResource>) -> ();
static_foo(&mut self) -> ()10     fn static_foo(&mut self) -> ();
drop( &mut self, rep: wasmtime::component::Resource<WorldResource>, ) -> wasmtime::Result<()>11     fn drop(
12         &mut self,
13         rep: wasmtime::component::Resource<WorldResource>,
14     ) -> wasmtime::Result<()>;
15 }
16 impl<_T: HostWorldResource + ?Sized> HostWorldResource for &mut _T {
new(&mut self) -> wasmtime::component::Resource<WorldResource>17     fn new(&mut self) -> wasmtime::component::Resource<WorldResource> {
18         HostWorldResource::new(*self)
19     }
foo(&mut self, self_: wasmtime::component::Resource<WorldResource>) -> ()20     fn foo(&mut self, self_: wasmtime::component::Resource<WorldResource>) -> () {
21         HostWorldResource::foo(*self, self_)
22     }
static_foo(&mut self) -> ()23     fn static_foo(&mut self) -> () {
24         HostWorldResource::static_foo(*self)
25     }
drop( &mut self, rep: wasmtime::component::Resource<WorldResource>, ) -> wasmtime::Result<()>26     fn drop(
27         &mut self,
28         rep: wasmtime::component::Resource<WorldResource>,
29     ) -> wasmtime::Result<()> {
30         HostWorldResource::drop(*self, rep)
31     }
32 }
33 /// Auto-generated bindings for a pre-instantiated version of a
34 /// component which implements the world `the-world`.
35 ///
36 /// This structure is created through [`TheWorldPre::new`] which
37 /// takes a [`InstancePre`](wasmtime::component::InstancePre) that
38 /// has been created through a [`Linker`](wasmtime::component::Linker).
39 ///
40 /// For more information see [`TheWorld`] as well.
41 pub struct TheWorldPre<T: 'static> {
42     instance_pre: wasmtime::component::InstancePre<T>,
43     indices: TheWorldIndices,
44 }
45 impl<T: 'static> Clone for TheWorldPre<T> {
clone(&self) -> Self46     fn clone(&self) -> Self {
47         Self {
48             instance_pre: self.instance_pre.clone(),
49             indices: self.indices.clone(),
50         }
51     }
52 }
53 impl<_T: 'static> TheWorldPre<_T> {
54     /// Creates a new copy of `TheWorldPre` bindings which can then
55     /// be used to instantiate into a particular store.
56     ///
57     /// This method may fail if the component behind `instance_pre`
58     /// does not have the required exports.
new( instance_pre: wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>59     pub fn new(
60         instance_pre: wasmtime::component::InstancePre<_T>,
61     ) -> wasmtime::Result<Self> {
62         let indices = TheWorldIndices::new(&instance_pre)?;
63         Ok(Self { instance_pre, indices })
64     }
engine(&self) -> &wasmtime::Engine65     pub fn engine(&self) -> &wasmtime::Engine {
66         self.instance_pre.engine()
67     }
instance_pre(&self) -> &wasmtime::component::InstancePre<_T>68     pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
69         &self.instance_pre
70     }
71     /// Instantiates a new instance of [`TheWorld`] within the
72     /// `store` provided.
73     ///
74     /// This function will use `self` as the pre-instantiated
75     /// instance to perform instantiation. Afterwards the preloaded
76     /// indices in `self` are used to lookup all exports on the
77     /// resulting instance.
instantiate( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<TheWorld>78     pub fn instantiate(
79         &self,
80         mut store: impl wasmtime::AsContextMut<Data = _T>,
81     ) -> wasmtime::Result<TheWorld> {
82         let mut store = store.as_context_mut();
83         let instance = self.instance_pre.instantiate(&mut store)?;
84         self.indices.load(&mut store, &instance)
85     }
86 }
87 impl<_T: Send + 'static> TheWorldPre<_T> {
88     /// Same as [`Self::instantiate`], except with `async`.
instantiate_async( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<TheWorld>89     pub async fn instantiate_async(
90         &self,
91         mut store: impl wasmtime::AsContextMut<Data = _T>,
92     ) -> wasmtime::Result<TheWorld> {
93         let mut store = store.as_context_mut();
94         let instance = self.instance_pre.instantiate_async(&mut store).await?;
95         self.indices.load(&mut store, &instance)
96     }
97 }
98 /// Auto-generated bindings for index of the exports of
99 /// `the-world`.
100 ///
101 /// This is an implementation detail of [`TheWorldPre`] and can
102 /// be constructed if needed as well.
103 ///
104 /// For more information see [`TheWorld`] as well.
105 #[derive(Clone)]
106 pub struct TheWorldIndices {
107     interface1: exports::foo::foo::uses_resource_transitively::GuestIndices,
108     some_world_func2: wasmtime::component::ComponentExportIndex,
109 }
110 /// Auto-generated bindings for an instance a component which
111 /// implements the world `the-world`.
112 ///
113 /// This structure can be created through a number of means
114 /// depending on your requirements and what you have on hand:
115 ///
116 /// * The most convenient way is to use
117 ///   [`TheWorld::instantiate`] which only needs a
118 ///   [`Store`], [`Component`], and [`Linker`].
119 ///
120 /// * Alternatively you can create a [`TheWorldPre`] ahead of
121 ///   time with a [`Component`] to front-load string lookups
122 ///   of exports once instead of per-instantiation. This
123 ///   method then uses [`TheWorldPre::instantiate`] to
124 ///   create a [`TheWorld`].
125 ///
126 /// * If you've instantiated the instance yourself already
127 ///   then you can use [`TheWorld::new`].
128 ///
129 /// These methods are all equivalent to one another and move
130 /// around the tradeoff of what work is performed when.
131 ///
132 /// [`Store`]: wasmtime::Store
133 /// [`Component`]: wasmtime::component::Component
134 /// [`Linker`]: wasmtime::component::Linker
135 pub struct TheWorld {
136     interface1: exports::foo::foo::uses_resource_transitively::Guest,
137     some_world_func2: wasmtime::component::Func,
138 }
139 pub trait TheWorldImportsWithStore: wasmtime::component::HasData + HostWorldResourceWithStore {}
140 impl<_T: ?Sized> TheWorldImportsWithStore for _T
141 where
142     _T: wasmtime::component::HasData + HostWorldResourceWithStore,
143 {}
144 pub trait TheWorldImports: HostWorldResource {
some_world_func(&mut self) -> wasmtime::component::Resource<WorldResource>145     fn some_world_func(&mut self) -> wasmtime::component::Resource<WorldResource>;
146 }
147 impl<_T: TheWorldImports + ?Sized> TheWorldImports for &mut _T {
some_world_func(&mut self) -> wasmtime::component::Resource<WorldResource>148     fn some_world_func(&mut self) -> wasmtime::component::Resource<WorldResource> {
149         TheWorldImports::some_world_func(*self)
150     }
151 }
152 const _: () = {
153     impl TheWorldIndices {
154         /// Creates a new copy of `TheWorldIndices` bindings which can then
155         /// be used to instantiate into a particular store.
156         ///
157         /// This method may fail if the component does not have the
158         /// required exports.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>159         pub fn new<_T>(
160             _instance_pre: &wasmtime::component::InstancePre<_T>,
161         ) -> wasmtime::Result<Self> {
162             let _component = _instance_pre.component();
163             let _instance_type = _instance_pre.instance_type();
164             let interface1 = exports::foo::foo::uses_resource_transitively::GuestIndices::new(
165                 _instance_pre,
166             )?;
167             let some_world_func2 = {
168                 let (item, index) = _component
169                     .get_export(None, "some-world-func2")
170                     .ok_or_else(|| {
171                         wasmtime::format_err!("no export `some-world-func2` found")
172                     })?;
173                 match item {
174                     wasmtime::component::types::ComponentItem::ComponentFunc(func) => {
175                         wasmtime::error::Context::context(
176                             func
177                                 .typecheck::<
178                                     (),
179                                     (wasmtime::component::Resource<WorldResource>,),
180                                 >(&_instance_type),
181                             "type-checking export func `some-world-func2`",
182                         )?;
183                         index
184                     }
185                     _ => {
186                         Err(
187                             wasmtime::format_err!(
188                                 "export `some-world-func2` is not a function"
189                             ),
190                         )?
191                     }
192                 }
193             };
194             Ok(TheWorldIndices {
195                 interface1,
196                 some_world_func2,
197             })
198         }
199         /// Uses the indices stored in `self` to load an instance
200         /// of [`TheWorld`] from the instance provided.
201         ///
202         /// Note that at this time this method will additionally
203         /// perform type-checks of all exports.
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<TheWorld>204         pub fn load(
205             &self,
206             mut store: impl wasmtime::AsContextMut,
207             instance: &wasmtime::component::Instance,
208         ) -> wasmtime::Result<TheWorld> {
209             let _ = &mut store;
210             let _instance = instance;
211             let interface1 = self.interface1.load(&mut store, &_instance)?;
212             let some_world_func2 = *_instance
213                 .get_typed_func::<
214                     (),
215                     (wasmtime::component::Resource<WorldResource>,),
216                 >(&mut store, &self.some_world_func2)?
217                 .func();
218             Ok(TheWorld {
219                 interface1,
220                 some_world_func2,
221             })
222         }
223     }
224     impl TheWorld {
225         /// Convenience wrapper around [`TheWorldPre::new`] and
226         /// [`TheWorldPre::instantiate`].
instantiate<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<TheWorld>227         pub fn instantiate<_T>(
228             store: impl wasmtime::AsContextMut<Data = _T>,
229             component: &wasmtime::component::Component,
230             linker: &wasmtime::component::Linker<_T>,
231         ) -> wasmtime::Result<TheWorld> {
232             let pre = linker.instantiate_pre(component)?;
233             TheWorldPre::new(pre)?.instantiate(store)
234         }
235         /// Convenience wrapper around [`TheWorldIndices::new`] and
236         /// [`TheWorldIndices::load`].
new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<TheWorld>237         pub fn new(
238             mut store: impl wasmtime::AsContextMut,
239             instance: &wasmtime::component::Instance,
240         ) -> wasmtime::Result<TheWorld> {
241             let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
242             indices.load(&mut store, instance)
243         }
244         /// Convenience wrapper around [`TheWorldPre::new`] and
245         /// [`TheWorldPre::instantiate_async`].
instantiate_async<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<TheWorld> where _T: Send,246         pub async fn instantiate_async<_T>(
247             store: impl wasmtime::AsContextMut<Data = _T>,
248             component: &wasmtime::component::Component,
249             linker: &wasmtime::component::Linker<_T>,
250         ) -> wasmtime::Result<TheWorld>
251         where
252             _T: Send,
253         {
254             let pre = linker.instantiate_pre(component)?;
255             TheWorldPre::new(pre)?.instantiate_async(store).await
256         }
add_to_linker_imports<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, T: 'static,257         pub fn add_to_linker_imports<T, D>(
258             linker: &mut wasmtime::component::Linker<T>,
259             host_getter: fn(&mut T) -> D::Data<'_>,
260         ) -> wasmtime::Result<()>
261         where
262             D: TheWorldImportsWithStore,
263             for<'a> D::Data<'a>: TheWorldImports,
264             T: 'static,
265         {
266             let mut linker = linker.root();
267             linker
268                 .resource(
269                     "world-resource",
270                     wasmtime::component::ResourceType::host::<WorldResource>(),
271                     move |mut store, rep| -> wasmtime::Result<()> {
272                         let resource = wasmtime::component::Resource::new_own(rep);
273                         wasmtime::ToWasmtimeResult::to_wasmtime_result(
274                             HostWorldResource::drop(
275                                 &mut host_getter(store.data_mut()),
276                                 resource,
277                             ),
278                         )
279                     },
280                 )?;
281             linker
282                 .func_wrap(
283                     "some-world-func",
284                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
285                         let host = &mut host_getter(caller.data_mut());
286                         let r = TheWorldImports::some_world_func(host);
287                         Ok((r,))
288                     },
289                 )?;
290             linker
291                 .func_wrap(
292                     "[constructor]world-resource",
293                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
294                         let host = &mut host_getter(caller.data_mut());
295                         let r = HostWorldResource::new(host);
296                         Ok((r,))
297                     },
298                 )?;
299             linker
300                 .func_wrap(
301                     "[method]world-resource.foo",
302                     move |
303                         mut caller: wasmtime::StoreContextMut<'_, T>,
304                         (arg0,): (wasmtime::component::Resource<WorldResource>,)|
305                     {
306                         let host = &mut host_getter(caller.data_mut());
307                         let r = HostWorldResource::foo(host, arg0);
308                         Ok(r)
309                     },
310                 )?;
311             linker
312                 .func_wrap(
313                     "[static]world-resource.static-foo",
314                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
315                         let host = &mut host_getter(caller.data_mut());
316                         let r = HostWorldResource::static_foo(host);
317                         Ok(r)
318                     },
319                 )?;
320             Ok(())
321         }
add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: foo::foo::resources::HostWithStore + foo::foo::long_use_chain1::HostWithStore + foo::foo::long_use_chain2::HostWithStore + foo::foo::long_use_chain3::HostWithStore + foo::foo::long_use_chain4::HostWithStore + foo::foo::transitive_interface_with_resource::HostWithStore + TheWorldImportsWithStore, for<'a> D::Data< 'a, >: foo::foo::resources::Host + foo::foo::long_use_chain1::Host + foo::foo::long_use_chain2::Host + foo::foo::long_use_chain3::Host + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports, T: 'static,322         pub fn add_to_linker<T, D>(
323             linker: &mut wasmtime::component::Linker<T>,
324             host_getter: fn(&mut T) -> D::Data<'_>,
325         ) -> wasmtime::Result<()>
326         where
327             D: foo::foo::resources::HostWithStore
328                 + foo::foo::long_use_chain1::HostWithStore
329                 + foo::foo::long_use_chain2::HostWithStore
330                 + foo::foo::long_use_chain3::HostWithStore
331                 + foo::foo::long_use_chain4::HostWithStore
332                 + foo::foo::transitive_interface_with_resource::HostWithStore
333                 + TheWorldImportsWithStore,
334             for<'a> D::Data<
335                 'a,
336             >: foo::foo::resources::Host + foo::foo::long_use_chain1::Host
337                 + foo::foo::long_use_chain2::Host + foo::foo::long_use_chain3::Host
338                 + foo::foo::long_use_chain4::Host
339                 + foo::foo::transitive_interface_with_resource::Host + TheWorldImports,
340             T: 'static,
341         {
342             Self::add_to_linker_imports::<T, D>(linker, host_getter)?;
343             foo::foo::resources::add_to_linker::<T, D>(linker, host_getter)?;
344             foo::foo::long_use_chain1::add_to_linker::<T, D>(linker, host_getter)?;
345             foo::foo::long_use_chain2::add_to_linker::<T, D>(linker, host_getter)?;
346             foo::foo::long_use_chain3::add_to_linker::<T, D>(linker, host_getter)?;
347             foo::foo::long_use_chain4::add_to_linker::<T, D>(linker, host_getter)?;
348             foo::foo::transitive_interface_with_resource::add_to_linker::<
349                 T,
350                 D,
351             >(linker, host_getter)?;
352             Ok(())
353         }
call_some_world_func2<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<wasmtime::component::Resource<WorldResource>>354         pub fn call_some_world_func2<S: wasmtime::AsContextMut>(
355             &self,
356             mut store: S,
357         ) -> wasmtime::Result<wasmtime::component::Resource<WorldResource>> {
358             let callee = unsafe {
359                 wasmtime::component::TypedFunc::<
360                     (),
361                     (wasmtime::component::Resource<WorldResource>,),
362                 >::new_unchecked(self.some_world_func2)
363             };
364             let (ret0,) = callee.call(store.as_context_mut(), ())?;
365             Ok(ret0)
366         }
foo_foo_uses_resource_transitively( &self, ) -> &exports::foo::foo::uses_resource_transitively::Guest367         pub fn foo_foo_uses_resource_transitively(
368             &self,
369         ) -> &exports::foo::foo::uses_resource_transitively::Guest {
370             &self.interface1
371         }
372     }
373 };
374 pub mod foo {
375     pub mod foo {
376         #[allow(clippy::all)]
377         pub mod resources {
378             #[allow(unused_imports)]
379             use wasmtime::component::__internal::Box;
380             pub enum Bar {}
381             pub trait HostBarWithStore: wasmtime::component::HasData {}
382             impl<_T: ?Sized> HostBarWithStore for _T
383             where
384                 _T: wasmtime::component::HasData,
385             {}
386             pub trait HostBar {
new(&mut self) -> wasmtime::component::Resource<Bar>387                 fn new(&mut self) -> wasmtime::component::Resource<Bar>;
static_a(&mut self) -> u32388                 fn static_a(&mut self) -> u32;
method_a(&mut self, self_: wasmtime::component::Resource<Bar>) -> u32389                 fn method_a(&mut self, self_: wasmtime::component::Resource<Bar>) -> u32;
drop( &mut self, rep: wasmtime::component::Resource<Bar>, ) -> wasmtime::Result<()>390                 fn drop(
391                     &mut self,
392                     rep: wasmtime::component::Resource<Bar>,
393                 ) -> wasmtime::Result<()>;
394             }
395             impl<_T: HostBar + ?Sized> HostBar for &mut _T {
new(&mut self) -> wasmtime::component::Resource<Bar>396                 fn new(&mut self) -> wasmtime::component::Resource<Bar> {
397                     HostBar::new(*self)
398                 }
static_a(&mut self) -> u32399                 fn static_a(&mut self) -> u32 {
400                     HostBar::static_a(*self)
401                 }
method_a( &mut self, self_: wasmtime::component::Resource<Bar>, ) -> u32402                 fn method_a(
403                     &mut self,
404                     self_: wasmtime::component::Resource<Bar>,
405                 ) -> u32 {
406                     HostBar::method_a(*self, self_)
407                 }
drop( &mut self, rep: wasmtime::component::Resource<Bar>, ) -> wasmtime::Result<()>408                 fn drop(
409                     &mut self,
410                     rep: wasmtime::component::Resource<Bar>,
411                 ) -> wasmtime::Result<()> {
412                     HostBar::drop(*self, rep)
413                 }
414             }
415             #[derive(wasmtime::component::ComponentType)]
416             #[derive(wasmtime::component::Lift)]
417             #[derive(wasmtime::component::Lower)]
418             #[component(record)]
419             pub struct NestedOwn {
420                 #[component(name = "nested-bar")]
421                 pub nested_bar: wasmtime::component::Resource<Bar>,
422             }
423             impl core::fmt::Debug for NestedOwn {
fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result424                 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
425                     f.debug_struct("NestedOwn")
426                         .field("nested-bar", &self.nested_bar)
427                         .finish()
428                 }
429             }
430             const _: () = {
431                 assert!(
432                     4 == < NestedOwn as wasmtime::component::ComponentType >::SIZE32
433                 );
434                 assert!(
435                     4 == < NestedOwn as wasmtime::component::ComponentType >::ALIGN32
436                 );
437             };
438             #[derive(wasmtime::component::ComponentType)]
439             #[derive(wasmtime::component::Lift)]
440             #[derive(wasmtime::component::Lower)]
441             #[component(record)]
442             pub struct NestedBorrow {
443                 #[component(name = "nested-bar")]
444                 pub nested_bar: wasmtime::component::Resource<Bar>,
445             }
446             impl core::fmt::Debug for NestedBorrow {
fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result447                 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
448                     f.debug_struct("NestedBorrow")
449                         .field("nested-bar", &self.nested_bar)
450                         .finish()
451                 }
452             }
453             const _: () = {
454                 assert!(
455                     4 == < NestedBorrow as wasmtime::component::ComponentType >::SIZE32
456                 );
457                 assert!(
458                     4 == < NestedBorrow as wasmtime::component::ComponentType >::ALIGN32
459                 );
460             };
461             pub type SomeHandle = wasmtime::component::Resource<Bar>;
462             const _: () = {
463                 assert!(
464                     4 == < SomeHandle as wasmtime::component::ComponentType >::SIZE32
465                 );
466                 assert!(
467                     4 == < SomeHandle as wasmtime::component::ComponentType >::ALIGN32
468                 );
469             };
470             pub enum Fallible {}
471             pub trait HostFallibleWithStore: wasmtime::component::HasData {}
472             impl<_T: ?Sized> HostFallibleWithStore for _T
473             where
474                 _T: wasmtime::component::HasData,
475             {}
476             pub trait HostFallible {
new( &mut self, ) -> Result< wasmtime::component::Resource<Fallible>, wasmtime::component::__internal::String, >477                 fn new(
478                     &mut self,
479                 ) -> Result<
480                     wasmtime::component::Resource<Fallible>,
481                     wasmtime::component::__internal::String,
482                 >;
drop( &mut self, rep: wasmtime::component::Resource<Fallible>, ) -> wasmtime::Result<()>483                 fn drop(
484                     &mut self,
485                     rep: wasmtime::component::Resource<Fallible>,
486                 ) -> wasmtime::Result<()>;
487             }
488             impl<_T: HostFallible + ?Sized> HostFallible for &mut _T {
new( &mut self, ) -> Result< wasmtime::component::Resource<Fallible>, wasmtime::component::__internal::String, >489                 fn new(
490                     &mut self,
491                 ) -> Result<
492                     wasmtime::component::Resource<Fallible>,
493                     wasmtime::component::__internal::String,
494                 > {
495                     HostFallible::new(*self)
496                 }
drop( &mut self, rep: wasmtime::component::Resource<Fallible>, ) -> wasmtime::Result<()>497                 fn drop(
498                     &mut self,
499                     rep: wasmtime::component::Resource<Fallible>,
500                 ) -> wasmtime::Result<()> {
501                     HostFallible::drop(*self, rep)
502                 }
503             }
504             pub trait HostWithStore: wasmtime::component::HasData + HostBarWithStore + HostFallibleWithStore {}
505             impl<_T: ?Sized> HostWithStore for _T
506             where
507                 _T: wasmtime::component::HasData + HostBarWithStore
508                     + HostFallibleWithStore,
509             {}
510             pub trait Host: HostBar + HostFallible {
bar_own_arg(&mut self, x: wasmtime::component::Resource<Bar>) -> ()511                 fn bar_own_arg(&mut self, x: wasmtime::component::Resource<Bar>) -> ();
bar_borrow_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> ()512                 fn bar_borrow_arg(
513                     &mut self,
514                     x: wasmtime::component::Resource<Bar>,
515                 ) -> ();
bar_result(&mut self) -> wasmtime::component::Resource<Bar>516                 fn bar_result(&mut self) -> wasmtime::component::Resource<Bar>;
tuple_own_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> ()517                 fn tuple_own_arg(
518                     &mut self,
519                     x: (wasmtime::component::Resource<Bar>, u32),
520                 ) -> ();
tuple_borrow_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> ()521                 fn tuple_borrow_arg(
522                     &mut self,
523                     x: (wasmtime::component::Resource<Bar>, u32),
524                 ) -> ();
tuple_result(&mut self) -> (wasmtime::component::Resource<Bar>, u32)525                 fn tuple_result(&mut self) -> (wasmtime::component::Resource<Bar>, u32);
option_own_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> ()526                 fn option_own_arg(
527                     &mut self,
528                     x: Option<wasmtime::component::Resource<Bar>>,
529                 ) -> ();
option_borrow_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> ()530                 fn option_borrow_arg(
531                     &mut self,
532                     x: Option<wasmtime::component::Resource<Bar>>,
533                 ) -> ();
option_result( &mut self, ) -> Option<wasmtime::component::Resource<Bar>>534                 fn option_result(
535                     &mut self,
536                 ) -> Option<wasmtime::component::Resource<Bar>>;
result_own_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> ()537                 fn result_own_arg(
538                     &mut self,
539                     x: Result<wasmtime::component::Resource<Bar>, ()>,
540                 ) -> ();
result_borrow_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> ()541                 fn result_borrow_arg(
542                     &mut self,
543                     x: Result<wasmtime::component::Resource<Bar>, ()>,
544                 ) -> ();
result_result( &mut self, ) -> Result<wasmtime::component::Resource<Bar>, ()>545                 fn result_result(
546                     &mut self,
547                 ) -> Result<wasmtime::component::Resource<Bar>, ()>;
list_own_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> ()548                 fn list_own_arg(
549                     &mut self,
550                     x: wasmtime::component::__internal::Vec<
551                         wasmtime::component::Resource<Bar>,
552                     >,
553                 ) -> ();
list_borrow_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> ()554                 fn list_borrow_arg(
555                     &mut self,
556                     x: wasmtime::component::__internal::Vec<
557                         wasmtime::component::Resource<Bar>,
558                     >,
559                 ) -> ();
list_result( &mut self, ) -> wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >560                 fn list_result(
561                     &mut self,
562                 ) -> wasmtime::component::__internal::Vec<
563                     wasmtime::component::Resource<Bar>,
564                 >;
record_own_arg(&mut self, x: NestedOwn) -> ()565                 fn record_own_arg(&mut self, x: NestedOwn) -> ();
record_borrow_arg(&mut self, x: NestedBorrow) -> ()566                 fn record_borrow_arg(&mut self, x: NestedBorrow) -> ();
record_result(&mut self) -> NestedOwn567                 fn record_result(&mut self) -> NestedOwn;
func_with_handle_typedef(&mut self, x: SomeHandle) -> ()568                 fn func_with_handle_typedef(&mut self, x: SomeHandle) -> ();
569             }
570             impl<_T: Host + ?Sized> Host for &mut _T {
bar_own_arg(&mut self, x: wasmtime::component::Resource<Bar>) -> ()571                 fn bar_own_arg(&mut self, x: wasmtime::component::Resource<Bar>) -> () {
572                     Host::bar_own_arg(*self, x)
573                 }
bar_borrow_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> ()574                 fn bar_borrow_arg(
575                     &mut self,
576                     x: wasmtime::component::Resource<Bar>,
577                 ) -> () {
578                     Host::bar_borrow_arg(*self, x)
579                 }
bar_result(&mut self) -> wasmtime::component::Resource<Bar>580                 fn bar_result(&mut self) -> wasmtime::component::Resource<Bar> {
581                     Host::bar_result(*self)
582                 }
tuple_own_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> ()583                 fn tuple_own_arg(
584                     &mut self,
585                     x: (wasmtime::component::Resource<Bar>, u32),
586                 ) -> () {
587                     Host::tuple_own_arg(*self, x)
588                 }
tuple_borrow_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> ()589                 fn tuple_borrow_arg(
590                     &mut self,
591                     x: (wasmtime::component::Resource<Bar>, u32),
592                 ) -> () {
593                     Host::tuple_borrow_arg(*self, x)
594                 }
tuple_result(&mut self) -> (wasmtime::component::Resource<Bar>, u32)595                 fn tuple_result(&mut self) -> (wasmtime::component::Resource<Bar>, u32) {
596                     Host::tuple_result(*self)
597                 }
option_own_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> ()598                 fn option_own_arg(
599                     &mut self,
600                     x: Option<wasmtime::component::Resource<Bar>>,
601                 ) -> () {
602                     Host::option_own_arg(*self, x)
603                 }
option_borrow_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> ()604                 fn option_borrow_arg(
605                     &mut self,
606                     x: Option<wasmtime::component::Resource<Bar>>,
607                 ) -> () {
608                     Host::option_borrow_arg(*self, x)
609                 }
option_result( &mut self, ) -> Option<wasmtime::component::Resource<Bar>>610                 fn option_result(
611                     &mut self,
612                 ) -> Option<wasmtime::component::Resource<Bar>> {
613                     Host::option_result(*self)
614                 }
result_own_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> ()615                 fn result_own_arg(
616                     &mut self,
617                     x: Result<wasmtime::component::Resource<Bar>, ()>,
618                 ) -> () {
619                     Host::result_own_arg(*self, x)
620                 }
result_borrow_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> ()621                 fn result_borrow_arg(
622                     &mut self,
623                     x: Result<wasmtime::component::Resource<Bar>, ()>,
624                 ) -> () {
625                     Host::result_borrow_arg(*self, x)
626                 }
result_result( &mut self, ) -> Result<wasmtime::component::Resource<Bar>, ()>627                 fn result_result(
628                     &mut self,
629                 ) -> Result<wasmtime::component::Resource<Bar>, ()> {
630                     Host::result_result(*self)
631                 }
list_own_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> ()632                 fn list_own_arg(
633                     &mut self,
634                     x: wasmtime::component::__internal::Vec<
635                         wasmtime::component::Resource<Bar>,
636                     >,
637                 ) -> () {
638                     Host::list_own_arg(*self, x)
639                 }
list_borrow_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> ()640                 fn list_borrow_arg(
641                     &mut self,
642                     x: wasmtime::component::__internal::Vec<
643                         wasmtime::component::Resource<Bar>,
644                     >,
645                 ) -> () {
646                     Host::list_borrow_arg(*self, x)
647                 }
list_result( &mut self, ) -> wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >648                 fn list_result(
649                     &mut self,
650                 ) -> wasmtime::component::__internal::Vec<
651                     wasmtime::component::Resource<Bar>,
652                 > {
653                     Host::list_result(*self)
654                 }
record_own_arg(&mut self, x: NestedOwn) -> ()655                 fn record_own_arg(&mut self, x: NestedOwn) -> () {
656                     Host::record_own_arg(*self, x)
657                 }
record_borrow_arg(&mut self, x: NestedBorrow) -> ()658                 fn record_borrow_arg(&mut self, x: NestedBorrow) -> () {
659                     Host::record_borrow_arg(*self, x)
660                 }
record_result(&mut self) -> NestedOwn661                 fn record_result(&mut self) -> NestedOwn {
662                     Host::record_result(*self)
663                 }
func_with_handle_typedef(&mut self, x: SomeHandle) -> ()664                 fn func_with_handle_typedef(&mut self, x: SomeHandle) -> () {
665                     Host::func_with_handle_typedef(*self, x)
666                 }
667             }
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,668             pub fn add_to_linker<T, D>(
669                 linker: &mut wasmtime::component::Linker<T>,
670                 host_getter: fn(&mut T) -> D::Data<'_>,
671             ) -> wasmtime::Result<()>
672             where
673                 D: HostWithStore,
674                 for<'a> D::Data<'a>: Host,
675                 T: 'static,
676             {
677                 let mut inst = linker.instance("foo:foo/resources")?;
678                 inst.resource(
679                     "bar",
680                     wasmtime::component::ResourceType::host::<Bar>(),
681                     move |mut store, rep| -> wasmtime::Result<()> {
682                         let resource = wasmtime::component::Resource::new_own(rep);
683                         wasmtime::ToWasmtimeResult::to_wasmtime_result(
684                             HostBar::drop(&mut host_getter(store.data_mut()), resource),
685                         )
686                     },
687                 )?;
688                 inst.resource(
689                     "fallible",
690                     wasmtime::component::ResourceType::host::<Fallible>(),
691                     move |mut store, rep| -> wasmtime::Result<()> {
692                         let resource = wasmtime::component::Resource::new_own(rep);
693                         wasmtime::ToWasmtimeResult::to_wasmtime_result(
694                             HostFallible::drop(
695                                 &mut host_getter(store.data_mut()),
696                                 resource,
697                             ),
698                         )
699                     },
700                 )?;
701                 inst.func_wrap(
702                     "[constructor]bar",
703                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
704                         let host = &mut host_getter(caller.data_mut());
705                         let r = HostBar::new(host);
706                         Ok((r,))
707                     },
708                 )?;
709                 inst.func_wrap(
710                     "[static]bar.static-a",
711                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
712                         let host = &mut host_getter(caller.data_mut());
713                         let r = HostBar::static_a(host);
714                         Ok((r,))
715                     },
716                 )?;
717                 inst.func_wrap(
718                     "[method]bar.method-a",
719                     move |
720                         mut caller: wasmtime::StoreContextMut<'_, T>,
721                         (arg0,): (wasmtime::component::Resource<Bar>,)|
722                     {
723                         let host = &mut host_getter(caller.data_mut());
724                         let r = HostBar::method_a(host, arg0);
725                         Ok((r,))
726                     },
727                 )?;
728                 inst.func_wrap(
729                     "bar-own-arg",
730                     move |
731                         mut caller: wasmtime::StoreContextMut<'_, T>,
732                         (arg0,): (wasmtime::component::Resource<Bar>,)|
733                     {
734                         let host = &mut host_getter(caller.data_mut());
735                         let r = Host::bar_own_arg(host, arg0);
736                         Ok(r)
737                     },
738                 )?;
739                 inst.func_wrap(
740                     "bar-borrow-arg",
741                     move |
742                         mut caller: wasmtime::StoreContextMut<'_, T>,
743                         (arg0,): (wasmtime::component::Resource<Bar>,)|
744                     {
745                         let host = &mut host_getter(caller.data_mut());
746                         let r = Host::bar_borrow_arg(host, arg0);
747                         Ok(r)
748                     },
749                 )?;
750                 inst.func_wrap(
751                     "bar-result",
752                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
753                         let host = &mut host_getter(caller.data_mut());
754                         let r = Host::bar_result(host);
755                         Ok((r,))
756                     },
757                 )?;
758                 inst.func_wrap(
759                     "tuple-own-arg",
760                     move |
761                         mut caller: wasmtime::StoreContextMut<'_, T>,
762                         (arg0,): ((wasmtime::component::Resource<Bar>, u32),)|
763                     {
764                         let host = &mut host_getter(caller.data_mut());
765                         let r = Host::tuple_own_arg(host, arg0);
766                         Ok(r)
767                     },
768                 )?;
769                 inst.func_wrap(
770                     "tuple-borrow-arg",
771                     move |
772                         mut caller: wasmtime::StoreContextMut<'_, T>,
773                         (arg0,): ((wasmtime::component::Resource<Bar>, u32),)|
774                     {
775                         let host = &mut host_getter(caller.data_mut());
776                         let r = Host::tuple_borrow_arg(host, arg0);
777                         Ok(r)
778                     },
779                 )?;
780                 inst.func_wrap(
781                     "tuple-result",
782                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
783                         let host = &mut host_getter(caller.data_mut());
784                         let r = Host::tuple_result(host);
785                         Ok((r,))
786                     },
787                 )?;
788                 inst.func_wrap(
789                     "option-own-arg",
790                     move |
791                         mut caller: wasmtime::StoreContextMut<'_, T>,
792                         (arg0,): (Option<wasmtime::component::Resource<Bar>>,)|
793                     {
794                         let host = &mut host_getter(caller.data_mut());
795                         let r = Host::option_own_arg(host, arg0);
796                         Ok(r)
797                     },
798                 )?;
799                 inst.func_wrap(
800                     "option-borrow-arg",
801                     move |
802                         mut caller: wasmtime::StoreContextMut<'_, T>,
803                         (arg0,): (Option<wasmtime::component::Resource<Bar>>,)|
804                     {
805                         let host = &mut host_getter(caller.data_mut());
806                         let r = Host::option_borrow_arg(host, arg0);
807                         Ok(r)
808                     },
809                 )?;
810                 inst.func_wrap(
811                     "option-result",
812                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
813                         let host = &mut host_getter(caller.data_mut());
814                         let r = Host::option_result(host);
815                         Ok((r,))
816                     },
817                 )?;
818                 inst.func_wrap(
819                     "result-own-arg",
820                     move |
821                         mut caller: wasmtime::StoreContextMut<'_, T>,
822                         (arg0,): (Result<wasmtime::component::Resource<Bar>, ()>,)|
823                     {
824                         let host = &mut host_getter(caller.data_mut());
825                         let r = Host::result_own_arg(host, arg0);
826                         Ok(r)
827                     },
828                 )?;
829                 inst.func_wrap(
830                     "result-borrow-arg",
831                     move |
832                         mut caller: wasmtime::StoreContextMut<'_, T>,
833                         (arg0,): (Result<wasmtime::component::Resource<Bar>, ()>,)|
834                     {
835                         let host = &mut host_getter(caller.data_mut());
836                         let r = Host::result_borrow_arg(host, arg0);
837                         Ok(r)
838                     },
839                 )?;
840                 inst.func_wrap(
841                     "result-result",
842                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
843                         let host = &mut host_getter(caller.data_mut());
844                         let r = Host::result_result(host);
845                         Ok((r,))
846                     },
847                 )?;
848                 inst.func_wrap(
849                     "list-own-arg",
850                     move |
851                         mut caller: wasmtime::StoreContextMut<'_, T>,
852                         (
853                             arg0,
854                         ): (
855                             wasmtime::component::__internal::Vec<
856                                 wasmtime::component::Resource<Bar>,
857                             >,
858                         )|
859                     {
860                         let host = &mut host_getter(caller.data_mut());
861                         let r = Host::list_own_arg(host, arg0);
862                         Ok(r)
863                     },
864                 )?;
865                 inst.func_wrap(
866                     "list-borrow-arg",
867                     move |
868                         mut caller: wasmtime::StoreContextMut<'_, T>,
869                         (
870                             arg0,
871                         ): (
872                             wasmtime::component::__internal::Vec<
873                                 wasmtime::component::Resource<Bar>,
874                             >,
875                         )|
876                     {
877                         let host = &mut host_getter(caller.data_mut());
878                         let r = Host::list_borrow_arg(host, arg0);
879                         Ok(r)
880                     },
881                 )?;
882                 inst.func_wrap(
883                     "list-result",
884                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
885                         let host = &mut host_getter(caller.data_mut());
886                         let r = Host::list_result(host);
887                         Ok((r,))
888                     },
889                 )?;
890                 inst.func_wrap(
891                     "record-own-arg",
892                     move |
893                         mut caller: wasmtime::StoreContextMut<'_, T>,
894                         (arg0,): (NestedOwn,)|
895                     {
896                         let host = &mut host_getter(caller.data_mut());
897                         let r = Host::record_own_arg(host, arg0);
898                         Ok(r)
899                     },
900                 )?;
901                 inst.func_wrap(
902                     "record-borrow-arg",
903                     move |
904                         mut caller: wasmtime::StoreContextMut<'_, T>,
905                         (arg0,): (NestedBorrow,)|
906                     {
907                         let host = &mut host_getter(caller.data_mut());
908                         let r = Host::record_borrow_arg(host, arg0);
909                         Ok(r)
910                     },
911                 )?;
912                 inst.func_wrap(
913                     "record-result",
914                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
915                         let host = &mut host_getter(caller.data_mut());
916                         let r = Host::record_result(host);
917                         Ok((r,))
918                     },
919                 )?;
920                 inst.func_wrap(
921                     "func-with-handle-typedef",
922                     move |
923                         mut caller: wasmtime::StoreContextMut<'_, T>,
924                         (arg0,): (SomeHandle,)|
925                     {
926                         let host = &mut host_getter(caller.data_mut());
927                         let r = Host::func_with_handle_typedef(host, arg0);
928                         Ok(r)
929                     },
930                 )?;
931                 inst.func_wrap(
932                     "[constructor]fallible",
933                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
934                         let host = &mut host_getter(caller.data_mut());
935                         let r = HostFallible::new(host);
936                         Ok((r,))
937                     },
938                 )?;
939                 Ok(())
940             }
941         }
942         #[allow(clippy::all)]
943         pub mod long_use_chain1 {
944             #[allow(unused_imports)]
945             use wasmtime::component::__internal::Box;
946             pub enum A {}
947             pub trait HostAWithStore: wasmtime::component::HasData {}
948             impl<_T: ?Sized> HostAWithStore for _T
949             where
950                 _T: wasmtime::component::HasData,
951             {}
952             pub trait HostA {
drop( &mut self, rep: wasmtime::component::Resource<A>, ) -> wasmtime::Result<()>953                 fn drop(
954                     &mut self,
955                     rep: wasmtime::component::Resource<A>,
956                 ) -> wasmtime::Result<()>;
957             }
958             impl<_T: HostA + ?Sized> HostA for &mut _T {
drop( &mut self, rep: wasmtime::component::Resource<A>, ) -> wasmtime::Result<()>959                 fn drop(
960                     &mut self,
961                     rep: wasmtime::component::Resource<A>,
962                 ) -> wasmtime::Result<()> {
963                     HostA::drop(*self, rep)
964                 }
965             }
966             pub trait HostWithStore: wasmtime::component::HasData + HostAWithStore {}
967             impl<_T: ?Sized> HostWithStore for _T
968             where
969                 _T: wasmtime::component::HasData + HostAWithStore,
970             {}
971             pub trait Host: HostA {}
972             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,973             pub fn add_to_linker<T, D>(
974                 linker: &mut wasmtime::component::Linker<T>,
975                 host_getter: fn(&mut T) -> D::Data<'_>,
976             ) -> wasmtime::Result<()>
977             where
978                 D: HostWithStore,
979                 for<'a> D::Data<'a>: Host,
980                 T: 'static,
981             {
982                 let mut inst = linker.instance("foo:foo/long-use-chain1")?;
983                 inst.resource(
984                     "a",
985                     wasmtime::component::ResourceType::host::<A>(),
986                     move |mut store, rep| -> wasmtime::Result<()> {
987                         let resource = wasmtime::component::Resource::new_own(rep);
988                         wasmtime::ToWasmtimeResult::to_wasmtime_result(
989                             HostA::drop(&mut host_getter(store.data_mut()), resource),
990                         )
991                     },
992                 )?;
993                 Ok(())
994             }
995         }
996         #[allow(clippy::all)]
997         pub mod long_use_chain2 {
998             #[allow(unused_imports)]
999             use wasmtime::component::__internal::Box;
1000             pub type A = super::super::super::foo::foo::long_use_chain1::A;
1001             pub trait HostWithStore: wasmtime::component::HasData {}
1002             impl<_T: ?Sized> HostWithStore for _T
1003             where
1004                 _T: wasmtime::component::HasData,
1005             {}
1006             pub trait Host {}
1007             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,1008             pub fn add_to_linker<T, D>(
1009                 linker: &mut wasmtime::component::Linker<T>,
1010                 host_getter: fn(&mut T) -> D::Data<'_>,
1011             ) -> wasmtime::Result<()>
1012             where
1013                 D: HostWithStore,
1014                 for<'a> D::Data<'a>: Host,
1015                 T: 'static,
1016             {
1017                 let mut inst = linker.instance("foo:foo/long-use-chain2")?;
1018                 Ok(())
1019             }
1020         }
1021         #[allow(clippy::all)]
1022         pub mod long_use_chain3 {
1023             #[allow(unused_imports)]
1024             use wasmtime::component::__internal::Box;
1025             pub type A = super::super::super::foo::foo::long_use_chain2::A;
1026             pub trait HostWithStore: wasmtime::component::HasData {}
1027             impl<_T: ?Sized> HostWithStore for _T
1028             where
1029                 _T: wasmtime::component::HasData,
1030             {}
1031             pub trait Host {}
1032             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,1033             pub fn add_to_linker<T, D>(
1034                 linker: &mut wasmtime::component::Linker<T>,
1035                 host_getter: fn(&mut T) -> D::Data<'_>,
1036             ) -> wasmtime::Result<()>
1037             where
1038                 D: HostWithStore,
1039                 for<'a> D::Data<'a>: Host,
1040                 T: 'static,
1041             {
1042                 let mut inst = linker.instance("foo:foo/long-use-chain3")?;
1043                 Ok(())
1044             }
1045         }
1046         #[allow(clippy::all)]
1047         pub mod long_use_chain4 {
1048             #[allow(unused_imports)]
1049             use wasmtime::component::__internal::Box;
1050             pub type A = super::super::super::foo::foo::long_use_chain3::A;
1051             pub trait HostWithStore: wasmtime::component::HasData {}
1052             impl<_T: ?Sized> HostWithStore for _T
1053             where
1054                 _T: wasmtime::component::HasData,
1055             {}
1056             pub trait Host {
foo(&mut self) -> wasmtime::component::Resource<A>1057                 fn foo(&mut self) -> wasmtime::component::Resource<A>;
1058             }
1059             impl<_T: Host + ?Sized> Host for &mut _T {
foo(&mut self) -> wasmtime::component::Resource<A>1060                 fn foo(&mut self) -> wasmtime::component::Resource<A> {
1061                     Host::foo(*self)
1062                 }
1063             }
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,1064             pub fn add_to_linker<T, D>(
1065                 linker: &mut wasmtime::component::Linker<T>,
1066                 host_getter: fn(&mut T) -> D::Data<'_>,
1067             ) -> wasmtime::Result<()>
1068             where
1069                 D: HostWithStore,
1070                 for<'a> D::Data<'a>: Host,
1071                 T: 'static,
1072             {
1073                 let mut inst = linker.instance("foo:foo/long-use-chain4")?;
1074                 inst.func_wrap(
1075                     "foo",
1076                     move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
1077                         let host = &mut host_getter(caller.data_mut());
1078                         let r = Host::foo(host);
1079                         Ok((r,))
1080                     },
1081                 )?;
1082                 Ok(())
1083             }
1084         }
1085         #[allow(clippy::all)]
1086         pub mod transitive_interface_with_resource {
1087             #[allow(unused_imports)]
1088             use wasmtime::component::__internal::Box;
1089             pub enum Foo {}
1090             pub trait HostFooWithStore: wasmtime::component::HasData {}
1091             impl<_T: ?Sized> HostFooWithStore for _T
1092             where
1093                 _T: wasmtime::component::HasData,
1094             {}
1095             pub trait HostFoo {
drop( &mut self, rep: wasmtime::component::Resource<Foo>, ) -> wasmtime::Result<()>1096                 fn drop(
1097                     &mut self,
1098                     rep: wasmtime::component::Resource<Foo>,
1099                 ) -> wasmtime::Result<()>;
1100             }
1101             impl<_T: HostFoo + ?Sized> HostFoo for &mut _T {
drop( &mut self, rep: wasmtime::component::Resource<Foo>, ) -> wasmtime::Result<()>1102                 fn drop(
1103                     &mut self,
1104                     rep: wasmtime::component::Resource<Foo>,
1105                 ) -> wasmtime::Result<()> {
1106                     HostFoo::drop(*self, rep)
1107                 }
1108             }
1109             pub trait HostWithStore: wasmtime::component::HasData + HostFooWithStore {}
1110             impl<_T: ?Sized> HostWithStore for _T
1111             where
1112                 _T: wasmtime::component::HasData + HostFooWithStore,
1113             {}
1114             pub trait Host: HostFoo {}
1115             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,1116             pub fn add_to_linker<T, D>(
1117                 linker: &mut wasmtime::component::Linker<T>,
1118                 host_getter: fn(&mut T) -> D::Data<'_>,
1119             ) -> wasmtime::Result<()>
1120             where
1121                 D: HostWithStore,
1122                 for<'a> D::Data<'a>: Host,
1123                 T: 'static,
1124             {
1125                 let mut inst = linker
1126                     .instance("foo:foo/transitive-interface-with-resource")?;
1127                 inst.resource(
1128                     "foo",
1129                     wasmtime::component::ResourceType::host::<Foo>(),
1130                     move |mut store, rep| -> wasmtime::Result<()> {
1131                         let resource = wasmtime::component::Resource::new_own(rep);
1132                         wasmtime::ToWasmtimeResult::to_wasmtime_result(
1133                             HostFoo::drop(&mut host_getter(store.data_mut()), resource),
1134                         )
1135                     },
1136                 )?;
1137                 Ok(())
1138             }
1139         }
1140     }
1141 }
1142 pub mod exports {
1143     pub mod foo {
1144         pub mod foo {
1145             #[allow(clippy::all)]
1146             pub mod uses_resource_transitively {
1147                 #[allow(unused_imports)]
1148                 use wasmtime::component::__internal::Box;
1149                 pub type Foo = super::super::super::super::foo::foo::transitive_interface_with_resource::Foo;
1150                 #[derive(Clone)]
1151                 pub struct Guest {
1152                     handle: wasmtime::component::Func,
1153                 }
1154                 #[derive(Clone)]
1155                 pub struct GuestIndices {
1156                     handle: wasmtime::component::ComponentExportIndex,
1157                 }
1158                 impl GuestIndices {
1159                     /// Constructor for [`GuestIndices`] which takes a
1160                     /// [`Component`](wasmtime::component::Component) as input and can be executed
1161                     /// before instantiation.
1162                     ///
1163                     /// This constructor can be used to front-load string lookups to find exports
1164                     /// within a component.
new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>1165                     pub fn new<_T>(
1166                         _instance_pre: &wasmtime::component::InstancePre<_T>,
1167                     ) -> wasmtime::Result<GuestIndices> {
1168                         let instance = _instance_pre
1169                             .component()
1170                             .get_export_index(None, "foo:foo/uses-resource-transitively")
1171                             .ok_or_else(|| {
1172                                 wasmtime::format_err!(
1173                                     "no exported instance named `foo:foo/uses-resource-transitively`"
1174                                 )
1175                             })?;
1176                         let mut lookup = move |name| {
1177                             _instance_pre
1178                                 .component()
1179                                 .get_export_index(Some(&instance), name)
1180                                 .ok_or_else(|| {
1181                                     wasmtime::format_err!(
1182                                         "instance export `foo:foo/uses-resource-transitively` does \
1183                                                                                 not have export `{name}`"
1184                                     )
1185                                 })
1186                         };
1187                         let _ = &mut lookup;
1188                         let handle = lookup("handle")?;
1189                         Ok(GuestIndices { handle })
1190                     }
load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>1191                     pub fn load(
1192                         &self,
1193                         mut store: impl wasmtime::AsContextMut,
1194                         instance: &wasmtime::component::Instance,
1195                     ) -> wasmtime::Result<Guest> {
1196                         let _instance = instance;
1197                         let _instance_pre = _instance.instance_pre(&store);
1198                         let _instance_type = _instance_pre.instance_type();
1199                         let mut store = store.as_context_mut();
1200                         let _ = &mut store;
1201                         let handle = *_instance
1202                             .get_typed_func::<
1203                                 (wasmtime::component::Resource<Foo>,),
1204                                 (),
1205                             >(&mut store, &self.handle)?
1206                             .func();
1207                         Ok(Guest { handle })
1208                     }
1209                 }
1210                 impl Guest {
call_handle<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::Resource<Foo>, ) -> wasmtime::Result<()>1211                     pub fn call_handle<S: wasmtime::AsContextMut>(
1212                         &self,
1213                         mut store: S,
1214                         arg0: wasmtime::component::Resource<Foo>,
1215                     ) -> wasmtime::Result<()> {
1216                         let callee = unsafe {
1217                             wasmtime::component::TypedFunc::<
1218                                 (wasmtime::component::Resource<Foo>,),
1219                                 (),
1220                             >::new_unchecked(self.handle)
1221                         };
1222                         let () = callee.call(store.as_context_mut(), (arg0,))?;
1223                         Ok(())
1224                     }
1225                 }
1226             }
1227         }
1228     }
1229 }
1230