1 /// Auto-generated bindings for a pre-instantiated version of a
2 /// component which implements the world `path2`.
3 ///
4 /// This structure is created through [`Path2Pre::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 [`Path2`] as well.
9 pub struct Path2Pre<T> {
10     instance_pre: wasmtime::component::InstancePre<T>,
11     indices: Path2Indices,
12 }
13 impl<T> Clone for Path2Pre<T> {
14     fn clone(&self) -> Self {
15         Self {
16             instance_pre: self.instance_pre.clone(),
17             indices: self.indices.clone(),
18         }
19     }
20 }
21 impl<_T> Path2Pre<_T> {
22     /// Creates a new copy of `Path2Pre` bindings which can then
23     /// be used to instantiate into a particular store.
24     ///
25     /// This method may fail if the component behind `instance_pre`
26     /// does not have the required exports.
27     pub fn new(
28         instance_pre: wasmtime::component::InstancePre<_T>,
29     ) -> wasmtime::Result<Self> {
30         let indices = Path2Indices::new(instance_pre.component())?;
31         Ok(Self { instance_pre, indices })
32     }
33     pub fn engine(&self) -> &wasmtime::Engine {
34         self.instance_pre.engine()
35     }
36     pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
37         &self.instance_pre
38     }
39     /// Instantiates a new instance of [`Path2`] within the
40     /// `store` provided.
41     ///
42     /// This function will use `self` as the pre-instantiated
43     /// instance to perform instantiation. Afterwards the preloaded
44     /// indices in `self` are used to lookup all exports on the
45     /// resulting instance.
46     pub async fn instantiate_async(
47         &self,
48         mut store: impl wasmtime::AsContextMut<Data = _T>,
49     ) -> wasmtime::Result<Path2>
50     where
51         _T: Send,
52     {
53         let mut store = store.as_context_mut();
54         let instance = self.instance_pre.instantiate_async(&mut store).await?;
55         self.indices.load(&mut store, &instance)
56     }
57 }
58 /// Auto-generated bindings for index of the exports of
59 /// `path2`.
60 ///
61 /// This is an implementation detail of [`Path2Pre`] and can
62 /// be constructed if needed as well.
63 ///
64 /// For more information see [`Path2`] as well.
65 #[derive(Clone)]
66 pub struct Path2Indices {}
67 /// Auto-generated bindings for an instance a component which
68 /// implements the world `path2`.
69 ///
70 /// This structure can be created through a number of means
71 /// depending on your requirements and what you have on hand:
72 ///
73 /// * The most convenient way is to use
74 ///   [`Path2::instantiate_async`] which only needs a
75 ///   [`Store`], [`Component`], and [`Linker`].
76 ///
77 /// * Alternatively you can create a [`Path2Pre`] ahead of
78 ///   time with a [`Component`] to front-load string lookups
79 ///   of exports once instead of per-instantiation. This
80 ///   method then uses [`Path2Pre::instantiate_async`] to
81 ///   create a [`Path2`].
82 ///
83 /// * If you've instantiated the instance yourself already
84 ///   then you can use [`Path2::new`].
85 ///
86 /// * You can also access the guts of instantiation through
87 ///   [`Path2Indices::new_instance`] followed
88 ///   by [`Path2Indices::load`] to crate an instance of this
89 ///   type.
90 ///
91 /// These methods are all equivalent to one another and move
92 /// around the tradeoff of what work is performed when.
93 ///
94 /// [`Store`]: wasmtime::Store
95 /// [`Component`]: wasmtime::component::Component
96 /// [`Linker`]: wasmtime::component::Linker
97 pub struct Path2 {}
98 const _: () = {
99     #[allow(unused_imports)]
100     use wasmtime::component::__internal::anyhow;
101     impl Path2Indices {
102         /// Creates a new copy of `Path2Indices` bindings which can then
103         /// be used to instantiate into a particular store.
104         ///
105         /// This method may fail if the component does not have the
106         /// required exports.
107         pub fn new(
108             component: &wasmtime::component::Component,
109         ) -> wasmtime::Result<Self> {
110             let _component = component;
111             Ok(Path2Indices {})
112         }
113         /// Creates a new instance of [`Path2Indices`] from an
114         /// instantiated component.
115         ///
116         /// This method of creating a [`Path2`] will perform string
117         /// lookups for all exports when this method is called. This
118         /// will only succeed if the provided instance matches the
119         /// requirements of [`Path2`].
120         pub fn new_instance(
121             mut store: impl wasmtime::AsContextMut,
122             instance: &wasmtime::component::Instance,
123         ) -> wasmtime::Result<Self> {
124             let _instance = instance;
125             Ok(Path2Indices {})
126         }
127         /// Uses the indices stored in `self` to load an instance
128         /// of [`Path2`] from the instance provided.
129         ///
130         /// Note that at this time this method will additionally
131         /// perform type-checks of all exports.
132         pub fn load(
133             &self,
134             mut store: impl wasmtime::AsContextMut,
135             instance: &wasmtime::component::Instance,
136         ) -> wasmtime::Result<Path2> {
137             let _instance = instance;
138             Ok(Path2 {})
139         }
140     }
141     impl Path2 {
142         /// Convenience wrapper around [`Path2Pre::new`] and
143         /// [`Path2Pre::instantiate_async`].
144         pub async fn instantiate_async<_T>(
145             mut store: impl wasmtime::AsContextMut<Data = _T>,
146             component: &wasmtime::component::Component,
147             linker: &wasmtime::component::Linker<_T>,
148         ) -> wasmtime::Result<Path2>
149         where
150             _T: Send,
151         {
152             let pre = linker.instantiate_pre(component)?;
153             Path2Pre::new(pre)?.instantiate_async(store).await
154         }
155         /// Convenience wrapper around [`Path2Indices::new_instance`] and
156         /// [`Path2Indices::load`].
157         pub fn new(
158             mut store: impl wasmtime::AsContextMut,
159             instance: &wasmtime::component::Instance,
160         ) -> wasmtime::Result<Path2> {
161             let indices = Path2Indices::new_instance(&mut store, instance)?;
162             indices.load(store, instance)
163         }
164         pub fn add_to_linker<T, U>(
165             linker: &mut wasmtime::component::Linker<T>,
166             get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
167         ) -> wasmtime::Result<()>
168         where
169             T: Send,
170             U: paths::path2::test::Host + Send,
171         {
172             paths::path2::test::add_to_linker(linker, get)?;
173             Ok(())
174         }
175     }
176 };
177 pub mod paths {
178     pub mod path2 {
179         #[allow(clippy::all)]
180         pub mod test {
181             #[allow(unused_imports)]
182             use wasmtime::component::__internal::anyhow;
183             #[wasmtime::component::__internal::async_trait]
184             pub trait Host: Send {}
185             pub trait GetHost<
186                 T,
187             >: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
188                 type Host: Host + Send;
189             }
190             impl<F, T, O> GetHost<T> for F
191             where
192                 F: Fn(T) -> O + Send + Sync + Copy + 'static,
193                 O: Host + Send,
194             {
195                 type Host = O;
196             }
197             pub fn add_to_linker_get_host<T>(
198                 linker: &mut wasmtime::component::Linker<T>,
199                 host_getter: impl for<'a> GetHost<&'a mut T>,
200             ) -> wasmtime::Result<()>
201             where
202                 T: Send,
203             {
204                 let mut inst = linker.instance("paths:path2/test")?;
205                 Ok(())
206             }
207             pub fn add_to_linker<T, U>(
208                 linker: &mut wasmtime::component::Linker<T>,
209                 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
210             ) -> wasmtime::Result<()>
211             where
212                 U: Host + Send,
213                 T: Send,
214             {
215                 add_to_linker_get_host(linker, get)
216             }
217             #[wasmtime::component::__internal::async_trait]
218             impl<_T: Host + ?Sized + Send> Host for &mut _T {}
219         }
220     }
221 }
222