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