1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// component which implements the world `d`. 3 /// 4 /// This structure is created through [`DPre::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 [`D`] as well. 9 pub struct DPre<T: 'static> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: DIndices, 12 } 13 impl<T: 'static> Clone for DPre<T> { 14 fn clone(&self) -> Self { 15 Self { 16 instance_pre: self.instance_pre.clone(), 17 indices: self.indices.clone(), 18 } 19 } 20 } 21 impl<_T: 'static> DPre<_T> { 22 /// Creates a new copy of `DPre` 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 = DIndices::new(&instance_pre)?; 31 Ok(Self { instance_pre, indices }) 32 } 33 pub fn engine(&self) -> &wasmtime::Engine { 34 self.instance_pre.engine() 35 } 36 pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> { 37 &self.instance_pre 38 } 39 /// Instantiates a new instance of [`D`] 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<D> 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 /// `d`. 60 /// 61 /// This is an implementation detail of [`DPre`] and can 62 /// be constructed if needed as well. 63 /// 64 /// For more information see [`D`] as well. 65 #[derive(Clone)] 66 pub struct DIndices {} 67 /// Auto-generated bindings for an instance a component which 68 /// implements the world `d`. 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 /// [`D::instantiate_async`] which only needs a 75 /// [`Store`], [`Component`], and [`Linker`]. 76 /// 77 /// * Alternatively you can create a [`DPre`] 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 [`DPre::instantiate_async`] to 81 /// create a [`D`]. 82 /// 83 /// * If you've instantiated the instance yourself already 84 /// then you can use [`D::new`]. 85 /// 86 /// These methods are all equivalent to one another and move 87 /// around the tradeoff of what work is performed when. 88 /// 89 /// [`Store`]: wasmtime::Store 90 /// [`Component`]: wasmtime::component::Component 91 /// [`Linker`]: wasmtime::component::Linker 92 pub struct D {} 93 const _: () = { 94 #[allow(unused_imports)] 95 use wasmtime::component::__internal::anyhow; 96 impl DIndices { 97 /// Creates a new copy of `DIndices` bindings which can then 98 /// be used to instantiate into a particular store. 99 /// 100 /// This method may fail if the component does not have the 101 /// required exports. 102 pub fn new<_T>( 103 _instance_pre: &wasmtime::component::InstancePre<_T>, 104 ) -> wasmtime::Result<Self> { 105 let _component = _instance_pre.component(); 106 let _instance_type = _instance_pre.instance_type(); 107 Ok(DIndices {}) 108 } 109 /// Uses the indices stored in `self` to load an instance 110 /// of [`D`] from the instance provided. 111 /// 112 /// Note that at this time this method will additionally 113 /// perform type-checks of all exports. 114 pub fn load( 115 &self, 116 mut store: impl wasmtime::AsContextMut, 117 instance: &wasmtime::component::Instance, 118 ) -> wasmtime::Result<D> { 119 let _ = &mut store; 120 let _instance = instance; 121 Ok(D {}) 122 } 123 } 124 impl D { 125 /// Convenience wrapper around [`DPre::new`] and 126 /// [`DPre::instantiate_async`]. 127 pub async fn instantiate_async<_T>( 128 store: impl wasmtime::AsContextMut<Data = _T>, 129 component: &wasmtime::component::Component, 130 linker: &wasmtime::component::Linker<_T>, 131 ) -> wasmtime::Result<D> 132 where 133 _T: Send, 134 { 135 let pre = linker.instantiate_pre(component)?; 136 DPre::new(pre)?.instantiate_async(store).await 137 } 138 /// Convenience wrapper around [`DIndices::new`] and 139 /// [`DIndices::load`]. 140 pub fn new( 141 mut store: impl wasmtime::AsContextMut, 142 instance: &wasmtime::component::Instance, 143 ) -> wasmtime::Result<D> { 144 let indices = DIndices::new(&instance.instance_pre(&store))?; 145 indices.load(&mut store, instance) 146 } 147 pub fn add_to_linker<T, D>( 148 linker: &mut wasmtime::component::Linker<T>, 149 host_getter: fn(&mut T) -> D::Data<'_>, 150 ) -> wasmtime::Result<()> 151 where 152 D: foo::foo::a::HostConcurrent + foo::foo::b::HostConcurrent 153 + foo::foo::c::HostConcurrent + d::HostConcurrent + Send, 154 for<'a> D::Data< 155 'a, 156 >: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host 157 + Send, 158 T: 'static + Send, 159 { 160 foo::foo::a::add_to_linker::<T, D>(linker, host_getter)?; 161 foo::foo::b::add_to_linker::<T, D>(linker, host_getter)?; 162 foo::foo::c::add_to_linker::<T, D>(linker, host_getter)?; 163 d::add_to_linker::<T, D>(linker, host_getter)?; 164 Ok(()) 165 } 166 } 167 }; 168 pub mod foo { 169 pub mod foo { 170 #[allow(clippy::all)] 171 pub mod a { 172 #[allow(unused_imports)] 173 use wasmtime::component::__internal::{anyhow, Box}; 174 #[derive(wasmtime::component::ComponentType)] 175 #[derive(wasmtime::component::Lift)] 176 #[derive(wasmtime::component::Lower)] 177 #[component(record)] 178 #[derive(Clone, Copy)] 179 pub struct Foo {} 180 impl core::fmt::Debug for Foo { 181 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 182 f.debug_struct("Foo").finish() 183 } 184 } 185 const _: () = { 186 assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32); 187 assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); 188 }; 189 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 190 pub trait HostConcurrent: wasmtime::component::HasData + Send { 191 fn a<T: 'static>( 192 accessor: &mut wasmtime::component::Accessor<T, Self>, 193 ) -> impl ::core::future::Future<Output = Foo> + Send 194 where 195 Self: Sized; 196 } 197 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 198 pub trait Host: Send {} 199 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 200 pub fn add_to_linker<T, D>( 201 linker: &mut wasmtime::component::Linker<T>, 202 host_getter: fn(&mut T) -> D::Data<'_>, 203 ) -> wasmtime::Result<()> 204 where 205 D: HostConcurrent, 206 for<'a> D::Data<'a>: Host, 207 T: 'static + Send, 208 { 209 let mut inst = linker.instance("foo:foo/a")?; 210 inst.func_wrap_concurrent( 211 "a", 212 move |caller: &mut wasmtime::component::Accessor<T>, (): ()| { 213 wasmtime::component::__internal::Box::pin(async move { 214 let accessor = &mut unsafe { caller.with_data(host_getter) }; 215 let r = <D as HostConcurrent>::a(accessor).await; 216 Ok((r,)) 217 }) 218 }, 219 )?; 220 Ok(()) 221 } 222 } 223 #[allow(clippy::all)] 224 pub mod b { 225 #[allow(unused_imports)] 226 use wasmtime::component::__internal::{anyhow, Box}; 227 pub type Foo = super::super::super::foo::foo::a::Foo; 228 const _: () = { 229 assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32); 230 assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); 231 }; 232 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 233 pub trait HostConcurrent: wasmtime::component::HasData + Send { 234 fn a<T: 'static>( 235 accessor: &mut wasmtime::component::Accessor<T, Self>, 236 ) -> impl ::core::future::Future<Output = Foo> + Send 237 where 238 Self: Sized; 239 } 240 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 241 pub trait Host: Send {} 242 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 243 pub fn add_to_linker<T, D>( 244 linker: &mut wasmtime::component::Linker<T>, 245 host_getter: fn(&mut T) -> D::Data<'_>, 246 ) -> wasmtime::Result<()> 247 where 248 D: HostConcurrent, 249 for<'a> D::Data<'a>: Host, 250 T: 'static + Send, 251 { 252 let mut inst = linker.instance("foo:foo/b")?; 253 inst.func_wrap_concurrent( 254 "a", 255 move |caller: &mut wasmtime::component::Accessor<T>, (): ()| { 256 wasmtime::component::__internal::Box::pin(async move { 257 let accessor = &mut unsafe { caller.with_data(host_getter) }; 258 let r = <D as HostConcurrent>::a(accessor).await; 259 Ok((r,)) 260 }) 261 }, 262 )?; 263 Ok(()) 264 } 265 } 266 #[allow(clippy::all)] 267 pub mod c { 268 #[allow(unused_imports)] 269 use wasmtime::component::__internal::{anyhow, Box}; 270 pub type Foo = super::super::super::foo::foo::b::Foo; 271 const _: () = { 272 assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32); 273 assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); 274 }; 275 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 276 pub trait HostConcurrent: wasmtime::component::HasData + Send { 277 fn a<T: 'static>( 278 accessor: &mut wasmtime::component::Accessor<T, Self>, 279 ) -> impl ::core::future::Future<Output = Foo> + Send 280 where 281 Self: Sized; 282 } 283 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 284 pub trait Host: Send {} 285 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 286 pub fn add_to_linker<T, D>( 287 linker: &mut wasmtime::component::Linker<T>, 288 host_getter: fn(&mut T) -> D::Data<'_>, 289 ) -> wasmtime::Result<()> 290 where 291 D: HostConcurrent, 292 for<'a> D::Data<'a>: Host, 293 T: 'static + Send, 294 { 295 let mut inst = linker.instance("foo:foo/c")?; 296 inst.func_wrap_concurrent( 297 "a", 298 move |caller: &mut wasmtime::component::Accessor<T>, (): ()| { 299 wasmtime::component::__internal::Box::pin(async move { 300 let accessor = &mut unsafe { caller.with_data(host_getter) }; 301 let r = <D as HostConcurrent>::a(accessor).await; 302 Ok((r,)) 303 }) 304 }, 305 )?; 306 Ok(()) 307 } 308 } 309 } 310 } 311 #[allow(clippy::all)] 312 pub mod d { 313 #[allow(unused_imports)] 314 use wasmtime::component::__internal::{anyhow, Box}; 315 pub type Foo = super::foo::foo::c::Foo; 316 const _: () = { 317 assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32); 318 assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); 319 }; 320 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 321 pub trait HostConcurrent: wasmtime::component::HasData + Send { 322 fn b<T: 'static>( 323 accessor: &mut wasmtime::component::Accessor<T, Self>, 324 ) -> impl ::core::future::Future<Output = Foo> + Send 325 where 326 Self: Sized; 327 } 328 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 329 pub trait Host: Send {} 330 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 331 pub fn add_to_linker<T, D>( 332 linker: &mut wasmtime::component::Linker<T>, 333 host_getter: fn(&mut T) -> D::Data<'_>, 334 ) -> wasmtime::Result<()> 335 where 336 D: HostConcurrent, 337 for<'a> D::Data<'a>: Host, 338 T: 'static + Send, 339 { 340 let mut inst = linker.instance("d")?; 341 inst.func_wrap_concurrent( 342 "b", 343 move |caller: &mut wasmtime::component::Accessor<T>, (): ()| { 344 wasmtime::component::__internal::Box::pin(async move { 345 let accessor = &mut unsafe { caller.with_data(host_getter) }; 346 let r = <D as HostConcurrent>::b(accessor).await; 347 Ok((r,)) 348 }) 349 }, 350 )?; 351 Ok(()) 352 } 353 } 354