1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// component which implements the world `my-world`. 3 /// 4 /// This structure is created through [`MyWorldPre::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 [`MyWorld`] as well. 9 pub struct MyWorldPre<T: 'static> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: MyWorldIndices, 12 } 13 impl<T: 'static> Clone for MyWorldPre<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> MyWorldPre<_T> { 22 /// Creates a new copy of `MyWorldPre` 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 = MyWorldIndices::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 [`MyWorld`] 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 fn instantiate( 47 &self, 48 mut store: impl wasmtime::AsContextMut<Data = _T>, 49 ) -> wasmtime::Result<MyWorld> { 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> MyWorldPre<_T> { 56 /// Same as [`Self::instantiate`], except with `async`. 57 pub async fn instantiate_async( 58 &self, 59 mut store: impl wasmtime::AsContextMut<Data = _T>, 60 ) -> wasmtime::Result<MyWorld> { 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 /// `my-world`. 68 /// 69 /// This is an implementation detail of [`MyWorldPre`] and can 70 /// be constructed if needed as well. 71 /// 72 /// For more information see [`MyWorld`] as well. 73 #[derive(Clone)] 74 pub struct MyWorldIndices { 75 interface0: exports::foo::foo::variants::GuestIndices, 76 } 77 /// Auto-generated bindings for an instance a component which 78 /// implements the world `my-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 /// [`MyWorld::instantiate`] which only needs a 85 /// [`Store`], [`Component`], and [`Linker`]. 86 /// 87 /// * Alternatively you can create a [`MyWorldPre`] 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 [`MyWorldPre::instantiate`] to 91 /// create a [`MyWorld`]. 92 /// 93 /// * If you've instantiated the instance yourself already 94 /// then you can use [`MyWorld::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 MyWorld { 103 interface0: exports::foo::foo::variants::Guest, 104 } 105 const _: () = { 106 impl MyWorldIndices { 107 /// Creates a new copy of `MyWorldIndices` 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. 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::variants::GuestIndices::new( 118 _instance_pre, 119 )?; 120 Ok(MyWorldIndices { interface0 }) 121 } 122 /// Uses the indices stored in `self` to load an instance 123 /// of [`MyWorld`] from the instance provided. 124 /// 125 /// Note that at this time this method will additionally 126 /// perform type-checks of all exports. 127 pub fn load( 128 &self, 129 mut store: impl wasmtime::AsContextMut, 130 instance: &wasmtime::component::Instance, 131 ) -> wasmtime::Result<MyWorld> { 132 let _ = &mut store; 133 let _instance = instance; 134 let interface0 = self.interface0.load(&mut store, &_instance)?; 135 Ok(MyWorld { interface0 }) 136 } 137 } 138 impl MyWorld { 139 /// Convenience wrapper around [`MyWorldPre::new`] and 140 /// [`MyWorldPre::instantiate`]. 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<MyWorld> { 146 let pre = linker.instantiate_pre(component)?; 147 MyWorldPre::new(pre)?.instantiate(store) 148 } 149 /// Convenience wrapper around [`MyWorldIndices::new`] and 150 /// [`MyWorldIndices::load`]. 151 pub fn new( 152 mut store: impl wasmtime::AsContextMut, 153 instance: &wasmtime::component::Instance, 154 ) -> wasmtime::Result<MyWorld> { 155 let indices = MyWorldIndices::new(&instance.instance_pre(&store))?; 156 indices.load(&mut store, instance) 157 } 158 /// Convenience wrapper around [`MyWorldPre::new`] and 159 /// [`MyWorldPre::instantiate_async`]. 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<MyWorld> 165 where 166 _T: Send, 167 { 168 let pre = linker.instantiate_pre(component)?; 169 MyWorldPre::new(pre)?.instantiate_async(store).await 170 } 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::variants::HostWithStore + Send, 177 for<'a> D::Data<'a>: foo::foo::variants::Host + Send, 178 T: 'static + Send, 179 { 180 foo::foo::variants::add_to_linker::<T, D>(linker, host_getter)?; 181 Ok(()) 182 } 183 pub fn foo_foo_variants(&self) -> &exports::foo::foo::variants::Guest { 184 &self.interface0 185 } 186 } 187 }; 188 pub mod foo { 189 pub mod foo { 190 #[allow(clippy::all)] 191 pub mod variants { 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(enum)] 198 #[derive(Clone, Copy, Eq, PartialEq)] 199 #[repr(u8)] 200 pub enum E1 { 201 #[component(name = "a")] 202 A, 203 } 204 impl core::fmt::Debug for E1 { 205 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 206 match self { 207 E1::A => f.debug_tuple("E1::A").finish(), 208 } 209 } 210 } 211 const _: () = { 212 assert!(1 == < E1 as wasmtime::component::ComponentType >::SIZE32); 213 assert!(1 == < E1 as wasmtime::component::ComponentType >::ALIGN32); 214 }; 215 #[derive(wasmtime::component::ComponentType)] 216 #[derive(wasmtime::component::Lift)] 217 #[derive(wasmtime::component::Lower)] 218 #[component(record)] 219 #[derive(Clone, Copy)] 220 pub struct Empty {} 221 impl core::fmt::Debug for Empty { 222 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 223 f.debug_struct("Empty").finish() 224 } 225 } 226 const _: () = { 227 assert!(0 == < Empty as wasmtime::component::ComponentType >::SIZE32); 228 assert!(1 == < Empty as wasmtime::component::ComponentType >::ALIGN32); 229 }; 230 #[derive(wasmtime::component::ComponentType)] 231 #[derive(wasmtime::component::Lift)] 232 #[derive(wasmtime::component::Lower)] 233 #[component(variant)] 234 #[derive(Clone)] 235 pub enum V1 { 236 #[component(name = "a")] 237 A, 238 #[component(name = "c")] 239 C(E1), 240 #[component(name = "d")] 241 D(wasmtime::component::__internal::String), 242 #[component(name = "e")] 243 E(Empty), 244 #[component(name = "f")] 245 F, 246 #[component(name = "g")] 247 G(u32), 248 } 249 impl core::fmt::Debug for V1 { 250 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 251 match self { 252 V1::A => f.debug_tuple("V1::A").finish(), 253 V1::C(e) => f.debug_tuple("V1::C").field(e).finish(), 254 V1::D(e) => f.debug_tuple("V1::D").field(e).finish(), 255 V1::E(e) => f.debug_tuple("V1::E").field(e).finish(), 256 V1::F => f.debug_tuple("V1::F").finish(), 257 V1::G(e) => f.debug_tuple("V1::G").field(e).finish(), 258 } 259 } 260 } 261 const _: () = { 262 assert!(12 == < V1 as wasmtime::component::ComponentType >::SIZE32); 263 assert!(4 == < V1 as wasmtime::component::ComponentType >::ALIGN32); 264 }; 265 #[derive(wasmtime::component::ComponentType)] 266 #[derive(wasmtime::component::Lift)] 267 #[derive(wasmtime::component::Lower)] 268 #[component(variant)] 269 #[derive(Clone, Copy)] 270 pub enum Casts1 { 271 #[component(name = "a")] 272 A(i32), 273 #[component(name = "b")] 274 B(f32), 275 } 276 impl core::fmt::Debug for Casts1 { 277 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 278 match self { 279 Casts1::A(e) => f.debug_tuple("Casts1::A").field(e).finish(), 280 Casts1::B(e) => f.debug_tuple("Casts1::B").field(e).finish(), 281 } 282 } 283 } 284 const _: () = { 285 assert!(8 == < Casts1 as wasmtime::component::ComponentType >::SIZE32); 286 assert!(4 == < Casts1 as wasmtime::component::ComponentType >::ALIGN32); 287 }; 288 #[derive(wasmtime::component::ComponentType)] 289 #[derive(wasmtime::component::Lift)] 290 #[derive(wasmtime::component::Lower)] 291 #[component(variant)] 292 #[derive(Clone, Copy)] 293 pub enum Casts2 { 294 #[component(name = "a")] 295 A(f64), 296 #[component(name = "b")] 297 B(f32), 298 } 299 impl core::fmt::Debug for Casts2 { 300 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 301 match self { 302 Casts2::A(e) => f.debug_tuple("Casts2::A").field(e).finish(), 303 Casts2::B(e) => f.debug_tuple("Casts2::B").field(e).finish(), 304 } 305 } 306 } 307 const _: () = { 308 assert!(16 == < Casts2 as wasmtime::component::ComponentType >::SIZE32); 309 assert!(8 == < Casts2 as wasmtime::component::ComponentType >::ALIGN32); 310 }; 311 #[derive(wasmtime::component::ComponentType)] 312 #[derive(wasmtime::component::Lift)] 313 #[derive(wasmtime::component::Lower)] 314 #[component(variant)] 315 #[derive(Clone, Copy)] 316 pub enum Casts3 { 317 #[component(name = "a")] 318 A(f64), 319 #[component(name = "b")] 320 B(u64), 321 } 322 impl core::fmt::Debug for Casts3 { 323 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 324 match self { 325 Casts3::A(e) => f.debug_tuple("Casts3::A").field(e).finish(), 326 Casts3::B(e) => f.debug_tuple("Casts3::B").field(e).finish(), 327 } 328 } 329 } 330 const _: () = { 331 assert!(16 == < Casts3 as wasmtime::component::ComponentType >::SIZE32); 332 assert!(8 == < Casts3 as wasmtime::component::ComponentType >::ALIGN32); 333 }; 334 #[derive(wasmtime::component::ComponentType)] 335 #[derive(wasmtime::component::Lift)] 336 #[derive(wasmtime::component::Lower)] 337 #[component(variant)] 338 #[derive(Clone, Copy)] 339 pub enum Casts4 { 340 #[component(name = "a")] 341 A(u32), 342 #[component(name = "b")] 343 B(i64), 344 } 345 impl core::fmt::Debug for Casts4 { 346 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 347 match self { 348 Casts4::A(e) => f.debug_tuple("Casts4::A").field(e).finish(), 349 Casts4::B(e) => f.debug_tuple("Casts4::B").field(e).finish(), 350 } 351 } 352 } 353 const _: () = { 354 assert!(16 == < Casts4 as wasmtime::component::ComponentType >::SIZE32); 355 assert!(8 == < Casts4 as wasmtime::component::ComponentType >::ALIGN32); 356 }; 357 #[derive(wasmtime::component::ComponentType)] 358 #[derive(wasmtime::component::Lift)] 359 #[derive(wasmtime::component::Lower)] 360 #[component(variant)] 361 #[derive(Clone, Copy)] 362 pub enum Casts5 { 363 #[component(name = "a")] 364 A(f32), 365 #[component(name = "b")] 366 B(i64), 367 } 368 impl core::fmt::Debug for Casts5 { 369 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 370 match self { 371 Casts5::A(e) => f.debug_tuple("Casts5::A").field(e).finish(), 372 Casts5::B(e) => f.debug_tuple("Casts5::B").field(e).finish(), 373 } 374 } 375 } 376 const _: () = { 377 assert!(16 == < Casts5 as wasmtime::component::ComponentType >::SIZE32); 378 assert!(8 == < Casts5 as wasmtime::component::ComponentType >::ALIGN32); 379 }; 380 #[derive(wasmtime::component::ComponentType)] 381 #[derive(wasmtime::component::Lift)] 382 #[derive(wasmtime::component::Lower)] 383 #[component(variant)] 384 #[derive(Clone, Copy)] 385 pub enum Casts6 { 386 #[component(name = "a")] 387 A((f32, u32)), 388 #[component(name = "b")] 389 B((u32, u32)), 390 } 391 impl core::fmt::Debug for Casts6 { 392 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 393 match self { 394 Casts6::A(e) => f.debug_tuple("Casts6::A").field(e).finish(), 395 Casts6::B(e) => f.debug_tuple("Casts6::B").field(e).finish(), 396 } 397 } 398 } 399 const _: () = { 400 assert!(12 == < Casts6 as wasmtime::component::ComponentType >::SIZE32); 401 assert!(4 == < Casts6 as wasmtime::component::ComponentType >::ALIGN32); 402 }; 403 #[derive(wasmtime::component::ComponentType)] 404 #[derive(wasmtime::component::Lift)] 405 #[derive(wasmtime::component::Lower)] 406 #[component(enum)] 407 #[derive(Clone, Copy, Eq, PartialEq)] 408 #[repr(u8)] 409 pub enum MyErrno { 410 #[component(name = "bad1")] 411 Bad1, 412 #[component(name = "bad2")] 413 Bad2, 414 } 415 impl MyErrno { 416 pub fn name(&self) -> &'static str { 417 match self { 418 MyErrno::Bad1 => "bad1", 419 MyErrno::Bad2 => "bad2", 420 } 421 } 422 pub fn message(&self) -> &'static str { 423 match self { 424 MyErrno::Bad1 => "", 425 MyErrno::Bad2 => "", 426 } 427 } 428 } 429 impl core::fmt::Debug for MyErrno { 430 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 431 f.debug_struct("MyErrno") 432 .field("code", &(*self as i32)) 433 .field("name", &self.name()) 434 .field("message", &self.message()) 435 .finish() 436 } 437 } 438 impl core::fmt::Display for MyErrno { 439 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 440 write!(f, "{} (error {})", self.name(), * self as i32) 441 } 442 } 443 impl core::error::Error for MyErrno {} 444 const _: () = { 445 assert!(1 == < MyErrno as wasmtime::component::ComponentType >::SIZE32); 446 assert!(1 == < MyErrno as wasmtime::component::ComponentType >::ALIGN32); 447 }; 448 #[derive(wasmtime::component::ComponentType)] 449 #[derive(wasmtime::component::Lift)] 450 #[derive(wasmtime::component::Lower)] 451 #[component(record)] 452 #[derive(Clone)] 453 pub struct IsClone { 454 #[component(name = "v1")] 455 pub v1: V1, 456 } 457 impl core::fmt::Debug for IsClone { 458 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 459 f.debug_struct("IsClone").field("v1", &self.v1).finish() 460 } 461 } 462 const _: () = { 463 assert!(12 == < IsClone as wasmtime::component::ComponentType >::SIZE32); 464 assert!(4 == < IsClone as wasmtime::component::ComponentType >::ALIGN32); 465 }; 466 pub trait HostWithStore: wasmtime::component::HasData + Send { 467 fn e1_arg<T: Send>( 468 accessor: &wasmtime::component::Accessor<T, Self>, 469 x: E1, 470 ) -> impl ::core::future::Future<Output = ()> + Send; 471 fn e1_result<T: Send>( 472 accessor: &wasmtime::component::Accessor<T, Self>, 473 ) -> impl ::core::future::Future<Output = E1> + Send; 474 fn v1_arg<T: Send>( 475 accessor: &wasmtime::component::Accessor<T, Self>, 476 x: V1, 477 ) -> impl ::core::future::Future<Output = ()> + Send; 478 fn v1_result<T: Send>( 479 accessor: &wasmtime::component::Accessor<T, Self>, 480 ) -> impl ::core::future::Future<Output = V1> + Send; 481 fn bool_arg<T: Send>( 482 accessor: &wasmtime::component::Accessor<T, Self>, 483 x: bool, 484 ) -> impl ::core::future::Future<Output = ()> + Send; 485 fn bool_result<T: Send>( 486 accessor: &wasmtime::component::Accessor<T, Self>, 487 ) -> impl ::core::future::Future<Output = bool> + Send; 488 fn option_arg<T: Send>( 489 accessor: &wasmtime::component::Accessor<T, Self>, 490 a: Option<bool>, 491 b: Option<()>, 492 c: Option<u32>, 493 d: Option<E1>, 494 e: Option<f32>, 495 g: Option<Option<bool>>, 496 ) -> impl ::core::future::Future<Output = ()> + Send; 497 fn option_result<T: Send>( 498 accessor: &wasmtime::component::Accessor<T, Self>, 499 ) -> impl ::core::future::Future< 500 Output = ( 501 Option<bool>, 502 Option<()>, 503 Option<u32>, 504 Option<E1>, 505 Option<f32>, 506 Option<Option<bool>>, 507 ), 508 > + Send; 509 fn casts<T: Send>( 510 accessor: &wasmtime::component::Accessor<T, Self>, 511 a: Casts1, 512 b: Casts2, 513 c: Casts3, 514 d: Casts4, 515 e: Casts5, 516 f: Casts6, 517 ) -> impl ::core::future::Future< 518 Output = (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), 519 > + Send; 520 fn result_arg<T: Send>( 521 accessor: &wasmtime::component::Accessor<T, Self>, 522 a: Result<(), ()>, 523 b: Result<(), E1>, 524 c: Result<E1, ()>, 525 d: Result<(), ()>, 526 e: Result<u32, V1>, 527 f: Result< 528 wasmtime::component::__internal::String, 529 wasmtime::component::__internal::Vec<u8>, 530 >, 531 ) -> impl ::core::future::Future<Output = ()> + Send; 532 fn result_result<T: Send>( 533 accessor: &wasmtime::component::Accessor<T, Self>, 534 ) -> impl ::core::future::Future< 535 Output = ( 536 Result<(), ()>, 537 Result<(), E1>, 538 Result<E1, ()>, 539 Result<(), ()>, 540 Result<u32, V1>, 541 Result< 542 wasmtime::component::__internal::String, 543 wasmtime::component::__internal::Vec<u8>, 544 >, 545 ), 546 > + Send; 547 fn return_result_sugar<T: Send>( 548 accessor: &wasmtime::component::Accessor<T, Self>, 549 ) -> impl ::core::future::Future<Output = Result<i32, MyErrno>> + Send; 550 fn return_result_sugar2<T: Send>( 551 accessor: &wasmtime::component::Accessor<T, Self>, 552 ) -> impl ::core::future::Future<Output = Result<(), MyErrno>> + Send; 553 fn return_result_sugar3<T: Send>( 554 accessor: &wasmtime::component::Accessor<T, Self>, 555 ) -> impl ::core::future::Future< 556 Output = Result<MyErrno, MyErrno>, 557 > + Send; 558 fn return_result_sugar4<T: Send>( 559 accessor: &wasmtime::component::Accessor<T, Self>, 560 ) -> impl ::core::future::Future< 561 Output = Result<(i32, u32), MyErrno>, 562 > + Send; 563 fn return_option_sugar<T: Send>( 564 accessor: &wasmtime::component::Accessor<T, Self>, 565 ) -> impl ::core::future::Future<Output = Option<i32>> + Send; 566 fn return_option_sugar2<T: Send>( 567 accessor: &wasmtime::component::Accessor<T, Self>, 568 ) -> impl ::core::future::Future<Output = Option<MyErrno>> + Send; 569 fn result_simple<T: Send>( 570 accessor: &wasmtime::component::Accessor<T, Self>, 571 ) -> impl ::core::future::Future<Output = Result<u32, i32>> + Send; 572 fn is_clone_arg<T: Send>( 573 accessor: &wasmtime::component::Accessor<T, Self>, 574 a: IsClone, 575 ) -> impl ::core::future::Future<Output = ()> + Send; 576 fn is_clone_return<T: Send>( 577 accessor: &wasmtime::component::Accessor<T, Self>, 578 ) -> impl ::core::future::Future<Output = IsClone> + Send; 579 } 580 pub trait Host: Send {} 581 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 582 pub fn add_to_linker<T, D>( 583 linker: &mut wasmtime::component::Linker<T>, 584 host_getter: fn(&mut T) -> D::Data<'_>, 585 ) -> wasmtime::Result<()> 586 where 587 D: HostWithStore, 588 for<'a> D::Data<'a>: Host, 589 T: 'static + Send, 590 { 591 let mut inst = linker.instance("foo:foo/variants")?; 592 inst.func_wrap_concurrent( 593 "e1-arg", 594 move |caller: &wasmtime::component::Accessor<T>, (arg0,): (E1,)| { 595 wasmtime::component::__internal::Box::pin(async move { 596 let host = &caller.with_getter(host_getter); 597 let r = <D as HostWithStore>::e1_arg(host, arg0).await; 598 Ok(r) 599 }) 600 }, 601 )?; 602 inst.func_wrap_concurrent( 603 "e1-result", 604 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 605 wasmtime::component::__internal::Box::pin(async move { 606 let host = &caller.with_getter(host_getter); 607 let r = <D as HostWithStore>::e1_result(host).await; 608 Ok((r,)) 609 }) 610 }, 611 )?; 612 inst.func_wrap_concurrent( 613 "v1-arg", 614 move |caller: &wasmtime::component::Accessor<T>, (arg0,): (V1,)| { 615 wasmtime::component::__internal::Box::pin(async move { 616 let host = &caller.with_getter(host_getter); 617 let r = <D as HostWithStore>::v1_arg(host, arg0).await; 618 Ok(r) 619 }) 620 }, 621 )?; 622 inst.func_wrap_concurrent( 623 "v1-result", 624 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 625 wasmtime::component::__internal::Box::pin(async move { 626 let host = &caller.with_getter(host_getter); 627 let r = <D as HostWithStore>::v1_result(host).await; 628 Ok((r,)) 629 }) 630 }, 631 )?; 632 inst.func_wrap_concurrent( 633 "bool-arg", 634 move |caller: &wasmtime::component::Accessor<T>, (arg0,): (bool,)| { 635 wasmtime::component::__internal::Box::pin(async move { 636 let host = &caller.with_getter(host_getter); 637 let r = <D as HostWithStore>::bool_arg(host, arg0).await; 638 Ok(r) 639 }) 640 }, 641 )?; 642 inst.func_wrap_concurrent( 643 "bool-result", 644 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 645 wasmtime::component::__internal::Box::pin(async move { 646 let host = &caller.with_getter(host_getter); 647 let r = <D as HostWithStore>::bool_result(host).await; 648 Ok((r,)) 649 }) 650 }, 651 )?; 652 inst.func_wrap_concurrent( 653 "option-arg", 654 move | 655 caller: &wasmtime::component::Accessor<T>, 656 ( 657 arg0, 658 arg1, 659 arg2, 660 arg3, 661 arg4, 662 arg5, 663 ): ( 664 Option<bool>, 665 Option<()>, 666 Option<u32>, 667 Option<E1>, 668 Option<f32>, 669 Option<Option<bool>>, 670 )| 671 { 672 wasmtime::component::__internal::Box::pin(async move { 673 let host = &caller.with_getter(host_getter); 674 let r = <D as HostWithStore>::option_arg( 675 host, 676 arg0, 677 arg1, 678 arg2, 679 arg3, 680 arg4, 681 arg5, 682 ) 683 .await; 684 Ok(r) 685 }) 686 }, 687 )?; 688 inst.func_wrap_concurrent( 689 "option-result", 690 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 691 wasmtime::component::__internal::Box::pin(async move { 692 let host = &caller.with_getter(host_getter); 693 let r = <D as HostWithStore>::option_result(host).await; 694 Ok((r,)) 695 }) 696 }, 697 )?; 698 inst.func_wrap_concurrent( 699 "casts", 700 move | 701 caller: &wasmtime::component::Accessor<T>, 702 ( 703 arg0, 704 arg1, 705 arg2, 706 arg3, 707 arg4, 708 arg5, 709 ): (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6)| 710 { 711 wasmtime::component::__internal::Box::pin(async move { 712 let host = &caller.with_getter(host_getter); 713 let r = <D as HostWithStore>::casts( 714 host, 715 arg0, 716 arg1, 717 arg2, 718 arg3, 719 arg4, 720 arg5, 721 ) 722 .await; 723 Ok((r,)) 724 }) 725 }, 726 )?; 727 inst.func_wrap_concurrent( 728 "result-arg", 729 move | 730 caller: &wasmtime::component::Accessor<T>, 731 ( 732 arg0, 733 arg1, 734 arg2, 735 arg3, 736 arg4, 737 arg5, 738 ): ( 739 Result<(), ()>, 740 Result<(), E1>, 741 Result<E1, ()>, 742 Result<(), ()>, 743 Result<u32, V1>, 744 Result< 745 wasmtime::component::__internal::String, 746 wasmtime::component::__internal::Vec<u8>, 747 >, 748 )| 749 { 750 wasmtime::component::__internal::Box::pin(async move { 751 let host = &caller.with_getter(host_getter); 752 let r = <D as HostWithStore>::result_arg( 753 host, 754 arg0, 755 arg1, 756 arg2, 757 arg3, 758 arg4, 759 arg5, 760 ) 761 .await; 762 Ok(r) 763 }) 764 }, 765 )?; 766 inst.func_wrap_concurrent( 767 "result-result", 768 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 769 wasmtime::component::__internal::Box::pin(async move { 770 let host = &caller.with_getter(host_getter); 771 let r = <D as HostWithStore>::result_result(host).await; 772 Ok((r,)) 773 }) 774 }, 775 )?; 776 inst.func_wrap_concurrent( 777 "return-result-sugar", 778 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 779 wasmtime::component::__internal::Box::pin(async move { 780 let host = &caller.with_getter(host_getter); 781 let r = <D as HostWithStore>::return_result_sugar(host) 782 .await; 783 Ok((r,)) 784 }) 785 }, 786 )?; 787 inst.func_wrap_concurrent( 788 "return-result-sugar2", 789 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 790 wasmtime::component::__internal::Box::pin(async move { 791 let host = &caller.with_getter(host_getter); 792 let r = <D as HostWithStore>::return_result_sugar2(host) 793 .await; 794 Ok((r,)) 795 }) 796 }, 797 )?; 798 inst.func_wrap_concurrent( 799 "return-result-sugar3", 800 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 801 wasmtime::component::__internal::Box::pin(async move { 802 let host = &caller.with_getter(host_getter); 803 let r = <D as HostWithStore>::return_result_sugar3(host) 804 .await; 805 Ok((r,)) 806 }) 807 }, 808 )?; 809 inst.func_wrap_concurrent( 810 "return-result-sugar4", 811 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 812 wasmtime::component::__internal::Box::pin(async move { 813 let host = &caller.with_getter(host_getter); 814 let r = <D as HostWithStore>::return_result_sugar4(host) 815 .await; 816 Ok((r,)) 817 }) 818 }, 819 )?; 820 inst.func_wrap_concurrent( 821 "return-option-sugar", 822 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 823 wasmtime::component::__internal::Box::pin(async move { 824 let host = &caller.with_getter(host_getter); 825 let r = <D as HostWithStore>::return_option_sugar(host) 826 .await; 827 Ok((r,)) 828 }) 829 }, 830 )?; 831 inst.func_wrap_concurrent( 832 "return-option-sugar2", 833 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 834 wasmtime::component::__internal::Box::pin(async move { 835 let host = &caller.with_getter(host_getter); 836 let r = <D as HostWithStore>::return_option_sugar2(host) 837 .await; 838 Ok((r,)) 839 }) 840 }, 841 )?; 842 inst.func_wrap_concurrent( 843 "result-simple", 844 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 845 wasmtime::component::__internal::Box::pin(async move { 846 let host = &caller.with_getter(host_getter); 847 let r = <D as HostWithStore>::result_simple(host).await; 848 Ok((r,)) 849 }) 850 }, 851 )?; 852 inst.func_wrap_concurrent( 853 "is-clone-arg", 854 move | 855 caller: &wasmtime::component::Accessor<T>, 856 (arg0,): (IsClone,)| 857 { 858 wasmtime::component::__internal::Box::pin(async move { 859 let host = &caller.with_getter(host_getter); 860 let r = <D as HostWithStore>::is_clone_arg(host, arg0).await; 861 Ok(r) 862 }) 863 }, 864 )?; 865 inst.func_wrap_concurrent( 866 "is-clone-return", 867 move |caller: &wasmtime::component::Accessor<T>, (): ()| { 868 wasmtime::component::__internal::Box::pin(async move { 869 let host = &caller.with_getter(host_getter); 870 let r = <D as HostWithStore>::is_clone_return(host).await; 871 Ok((r,)) 872 }) 873 }, 874 )?; 875 Ok(()) 876 } 877 } 878 } 879 } 880 pub mod exports { 881 pub mod foo { 882 pub mod foo { 883 #[allow(clippy::all)] 884 pub mod variants { 885 #[allow(unused_imports)] 886 use wasmtime::component::__internal::Box; 887 #[derive(wasmtime::component::ComponentType)] 888 #[derive(wasmtime::component::Lift)] 889 #[derive(wasmtime::component::Lower)] 890 #[component(enum)] 891 #[derive(Clone, Copy, Eq, PartialEq)] 892 #[repr(u8)] 893 pub enum E1 { 894 #[component(name = "a")] 895 A, 896 } 897 impl core::fmt::Debug for E1 { 898 fn fmt( 899 &self, 900 f: &mut core::fmt::Formatter<'_>, 901 ) -> core::fmt::Result { 902 match self { 903 E1::A => f.debug_tuple("E1::A").finish(), 904 } 905 } 906 } 907 const _: () = { 908 assert!(1 == < E1 as wasmtime::component::ComponentType >::SIZE32); 909 assert!(1 == < E1 as wasmtime::component::ComponentType >::ALIGN32); 910 }; 911 #[derive(wasmtime::component::ComponentType)] 912 #[derive(wasmtime::component::Lift)] 913 #[derive(wasmtime::component::Lower)] 914 #[component(record)] 915 #[derive(Clone, Copy)] 916 pub struct Empty {} 917 impl core::fmt::Debug for Empty { 918 fn fmt( 919 &self, 920 f: &mut core::fmt::Formatter<'_>, 921 ) -> core::fmt::Result { 922 f.debug_struct("Empty").finish() 923 } 924 } 925 const _: () = { 926 assert!( 927 0 == < Empty as wasmtime::component::ComponentType >::SIZE32 928 ); 929 assert!( 930 1 == < Empty as wasmtime::component::ComponentType >::ALIGN32 931 ); 932 }; 933 #[derive(wasmtime::component::ComponentType)] 934 #[derive(wasmtime::component::Lift)] 935 #[derive(wasmtime::component::Lower)] 936 #[component(variant)] 937 #[derive(Clone)] 938 pub enum V1 { 939 #[component(name = "a")] 940 A, 941 #[component(name = "c")] 942 C(E1), 943 #[component(name = "d")] 944 D(wasmtime::component::__internal::String), 945 #[component(name = "e")] 946 E(Empty), 947 #[component(name = "f")] 948 F, 949 #[component(name = "g")] 950 G(u32), 951 } 952 impl core::fmt::Debug for V1 { 953 fn fmt( 954 &self, 955 f: &mut core::fmt::Formatter<'_>, 956 ) -> core::fmt::Result { 957 match self { 958 V1::A => f.debug_tuple("V1::A").finish(), 959 V1::C(e) => f.debug_tuple("V1::C").field(e).finish(), 960 V1::D(e) => f.debug_tuple("V1::D").field(e).finish(), 961 V1::E(e) => f.debug_tuple("V1::E").field(e).finish(), 962 V1::F => f.debug_tuple("V1::F").finish(), 963 V1::G(e) => f.debug_tuple("V1::G").field(e).finish(), 964 } 965 } 966 } 967 const _: () = { 968 assert!(12 == < V1 as wasmtime::component::ComponentType >::SIZE32); 969 assert!(4 == < V1 as wasmtime::component::ComponentType >::ALIGN32); 970 }; 971 #[derive(wasmtime::component::ComponentType)] 972 #[derive(wasmtime::component::Lift)] 973 #[derive(wasmtime::component::Lower)] 974 #[component(variant)] 975 #[derive(Clone, Copy)] 976 pub enum Casts1 { 977 #[component(name = "a")] 978 A(i32), 979 #[component(name = "b")] 980 B(f32), 981 } 982 impl core::fmt::Debug for Casts1 { 983 fn fmt( 984 &self, 985 f: &mut core::fmt::Formatter<'_>, 986 ) -> core::fmt::Result { 987 match self { 988 Casts1::A(e) => f.debug_tuple("Casts1::A").field(e).finish(), 989 Casts1::B(e) => f.debug_tuple("Casts1::B").field(e).finish(), 990 } 991 } 992 } 993 const _: () = { 994 assert!( 995 8 == < Casts1 as wasmtime::component::ComponentType >::SIZE32 996 ); 997 assert!( 998 4 == < Casts1 as wasmtime::component::ComponentType >::ALIGN32 999 ); 1000 }; 1001 #[derive(wasmtime::component::ComponentType)] 1002 #[derive(wasmtime::component::Lift)] 1003 #[derive(wasmtime::component::Lower)] 1004 #[component(variant)] 1005 #[derive(Clone, Copy)] 1006 pub enum Casts2 { 1007 #[component(name = "a")] 1008 A(f64), 1009 #[component(name = "b")] 1010 B(f32), 1011 } 1012 impl core::fmt::Debug for Casts2 { 1013 fn fmt( 1014 &self, 1015 f: &mut core::fmt::Formatter<'_>, 1016 ) -> core::fmt::Result { 1017 match self { 1018 Casts2::A(e) => f.debug_tuple("Casts2::A").field(e).finish(), 1019 Casts2::B(e) => f.debug_tuple("Casts2::B").field(e).finish(), 1020 } 1021 } 1022 } 1023 const _: () = { 1024 assert!( 1025 16 == < Casts2 as wasmtime::component::ComponentType >::SIZE32 1026 ); 1027 assert!( 1028 8 == < Casts2 as wasmtime::component::ComponentType >::ALIGN32 1029 ); 1030 }; 1031 #[derive(wasmtime::component::ComponentType)] 1032 #[derive(wasmtime::component::Lift)] 1033 #[derive(wasmtime::component::Lower)] 1034 #[component(variant)] 1035 #[derive(Clone, Copy)] 1036 pub enum Casts3 { 1037 #[component(name = "a")] 1038 A(f64), 1039 #[component(name = "b")] 1040 B(u64), 1041 } 1042 impl core::fmt::Debug for Casts3 { 1043 fn fmt( 1044 &self, 1045 f: &mut core::fmt::Formatter<'_>, 1046 ) -> core::fmt::Result { 1047 match self { 1048 Casts3::A(e) => f.debug_tuple("Casts3::A").field(e).finish(), 1049 Casts3::B(e) => f.debug_tuple("Casts3::B").field(e).finish(), 1050 } 1051 } 1052 } 1053 const _: () = { 1054 assert!( 1055 16 == < Casts3 as wasmtime::component::ComponentType >::SIZE32 1056 ); 1057 assert!( 1058 8 == < Casts3 as wasmtime::component::ComponentType >::ALIGN32 1059 ); 1060 }; 1061 #[derive(wasmtime::component::ComponentType)] 1062 #[derive(wasmtime::component::Lift)] 1063 #[derive(wasmtime::component::Lower)] 1064 #[component(variant)] 1065 #[derive(Clone, Copy)] 1066 pub enum Casts4 { 1067 #[component(name = "a")] 1068 A(u32), 1069 #[component(name = "b")] 1070 B(i64), 1071 } 1072 impl core::fmt::Debug for Casts4 { 1073 fn fmt( 1074 &self, 1075 f: &mut core::fmt::Formatter<'_>, 1076 ) -> core::fmt::Result { 1077 match self { 1078 Casts4::A(e) => f.debug_tuple("Casts4::A").field(e).finish(), 1079 Casts4::B(e) => f.debug_tuple("Casts4::B").field(e).finish(), 1080 } 1081 } 1082 } 1083 const _: () = { 1084 assert!( 1085 16 == < Casts4 as wasmtime::component::ComponentType >::SIZE32 1086 ); 1087 assert!( 1088 8 == < Casts4 as wasmtime::component::ComponentType >::ALIGN32 1089 ); 1090 }; 1091 #[derive(wasmtime::component::ComponentType)] 1092 #[derive(wasmtime::component::Lift)] 1093 #[derive(wasmtime::component::Lower)] 1094 #[component(variant)] 1095 #[derive(Clone, Copy)] 1096 pub enum Casts5 { 1097 #[component(name = "a")] 1098 A(f32), 1099 #[component(name = "b")] 1100 B(i64), 1101 } 1102 impl core::fmt::Debug for Casts5 { 1103 fn fmt( 1104 &self, 1105 f: &mut core::fmt::Formatter<'_>, 1106 ) -> core::fmt::Result { 1107 match self { 1108 Casts5::A(e) => f.debug_tuple("Casts5::A").field(e).finish(), 1109 Casts5::B(e) => f.debug_tuple("Casts5::B").field(e).finish(), 1110 } 1111 } 1112 } 1113 const _: () = { 1114 assert!( 1115 16 == < Casts5 as wasmtime::component::ComponentType >::SIZE32 1116 ); 1117 assert!( 1118 8 == < Casts5 as wasmtime::component::ComponentType >::ALIGN32 1119 ); 1120 }; 1121 #[derive(wasmtime::component::ComponentType)] 1122 #[derive(wasmtime::component::Lift)] 1123 #[derive(wasmtime::component::Lower)] 1124 #[component(variant)] 1125 #[derive(Clone, Copy)] 1126 pub enum Casts6 { 1127 #[component(name = "a")] 1128 A((f32, u32)), 1129 #[component(name = "b")] 1130 B((u32, u32)), 1131 } 1132 impl core::fmt::Debug for Casts6 { 1133 fn fmt( 1134 &self, 1135 f: &mut core::fmt::Formatter<'_>, 1136 ) -> core::fmt::Result { 1137 match self { 1138 Casts6::A(e) => f.debug_tuple("Casts6::A").field(e).finish(), 1139 Casts6::B(e) => f.debug_tuple("Casts6::B").field(e).finish(), 1140 } 1141 } 1142 } 1143 const _: () = { 1144 assert!( 1145 12 == < Casts6 as wasmtime::component::ComponentType >::SIZE32 1146 ); 1147 assert!( 1148 4 == < Casts6 as wasmtime::component::ComponentType >::ALIGN32 1149 ); 1150 }; 1151 #[derive(wasmtime::component::ComponentType)] 1152 #[derive(wasmtime::component::Lift)] 1153 #[derive(wasmtime::component::Lower)] 1154 #[component(enum)] 1155 #[derive(Clone, Copy, Eq, PartialEq)] 1156 #[repr(u8)] 1157 pub enum MyErrno { 1158 #[component(name = "bad1")] 1159 Bad1, 1160 #[component(name = "bad2")] 1161 Bad2, 1162 } 1163 impl MyErrno { 1164 pub fn name(&self) -> &'static str { 1165 match self { 1166 MyErrno::Bad1 => "bad1", 1167 MyErrno::Bad2 => "bad2", 1168 } 1169 } 1170 pub fn message(&self) -> &'static str { 1171 match self { 1172 MyErrno::Bad1 => "", 1173 MyErrno::Bad2 => "", 1174 } 1175 } 1176 } 1177 impl core::fmt::Debug for MyErrno { 1178 fn fmt( 1179 &self, 1180 f: &mut core::fmt::Formatter<'_>, 1181 ) -> core::fmt::Result { 1182 f.debug_struct("MyErrno") 1183 .field("code", &(*self as i32)) 1184 .field("name", &self.name()) 1185 .field("message", &self.message()) 1186 .finish() 1187 } 1188 } 1189 impl core::fmt::Display for MyErrno { 1190 fn fmt( 1191 &self, 1192 f: &mut core::fmt::Formatter<'_>, 1193 ) -> core::fmt::Result { 1194 write!(f, "{} (error {})", self.name(), * self as i32) 1195 } 1196 } 1197 impl core::error::Error for MyErrno {} 1198 const _: () = { 1199 assert!( 1200 1 == < MyErrno as wasmtime::component::ComponentType >::SIZE32 1201 ); 1202 assert!( 1203 1 == < MyErrno as wasmtime::component::ComponentType >::ALIGN32 1204 ); 1205 }; 1206 #[derive(wasmtime::component::ComponentType)] 1207 #[derive(wasmtime::component::Lift)] 1208 #[derive(wasmtime::component::Lower)] 1209 #[component(record)] 1210 #[derive(Clone)] 1211 pub struct IsClone { 1212 #[component(name = "v1")] 1213 pub v1: V1, 1214 } 1215 impl core::fmt::Debug for IsClone { 1216 fn fmt( 1217 &self, 1218 f: &mut core::fmt::Formatter<'_>, 1219 ) -> core::fmt::Result { 1220 f.debug_struct("IsClone").field("v1", &self.v1).finish() 1221 } 1222 } 1223 const _: () = { 1224 assert!( 1225 12 == < IsClone as wasmtime::component::ComponentType >::SIZE32 1226 ); 1227 assert!( 1228 4 == < IsClone as wasmtime::component::ComponentType >::ALIGN32 1229 ); 1230 }; 1231 #[derive(Clone)] 1232 pub struct Guest { 1233 e1_arg: wasmtime::component::Func, 1234 e1_result: wasmtime::component::Func, 1235 v1_arg: wasmtime::component::Func, 1236 v1_result: wasmtime::component::Func, 1237 bool_arg: wasmtime::component::Func, 1238 bool_result: wasmtime::component::Func, 1239 option_arg: wasmtime::component::Func, 1240 option_result: wasmtime::component::Func, 1241 casts: wasmtime::component::Func, 1242 result_arg: wasmtime::component::Func, 1243 result_result: wasmtime::component::Func, 1244 return_result_sugar: wasmtime::component::Func, 1245 return_result_sugar2: wasmtime::component::Func, 1246 return_result_sugar3: wasmtime::component::Func, 1247 return_result_sugar4: wasmtime::component::Func, 1248 return_option_sugar: wasmtime::component::Func, 1249 return_option_sugar2: wasmtime::component::Func, 1250 result_simple: wasmtime::component::Func, 1251 is_clone_arg: wasmtime::component::Func, 1252 is_clone_return: wasmtime::component::Func, 1253 } 1254 #[derive(Clone)] 1255 pub struct GuestIndices { 1256 e1_arg: wasmtime::component::ComponentExportIndex, 1257 e1_result: wasmtime::component::ComponentExportIndex, 1258 v1_arg: wasmtime::component::ComponentExportIndex, 1259 v1_result: wasmtime::component::ComponentExportIndex, 1260 bool_arg: wasmtime::component::ComponentExportIndex, 1261 bool_result: wasmtime::component::ComponentExportIndex, 1262 option_arg: wasmtime::component::ComponentExportIndex, 1263 option_result: wasmtime::component::ComponentExportIndex, 1264 casts: wasmtime::component::ComponentExportIndex, 1265 result_arg: wasmtime::component::ComponentExportIndex, 1266 result_result: wasmtime::component::ComponentExportIndex, 1267 return_result_sugar: wasmtime::component::ComponentExportIndex, 1268 return_result_sugar2: wasmtime::component::ComponentExportIndex, 1269 return_result_sugar3: wasmtime::component::ComponentExportIndex, 1270 return_result_sugar4: wasmtime::component::ComponentExportIndex, 1271 return_option_sugar: wasmtime::component::ComponentExportIndex, 1272 return_option_sugar2: wasmtime::component::ComponentExportIndex, 1273 result_simple: wasmtime::component::ComponentExportIndex, 1274 is_clone_arg: wasmtime::component::ComponentExportIndex, 1275 is_clone_return: wasmtime::component::ComponentExportIndex, 1276 } 1277 impl GuestIndices { 1278 /// Constructor for [`GuestIndices`] which takes a 1279 /// [`Component`](wasmtime::component::Component) as input and can be executed 1280 /// before instantiation. 1281 /// 1282 /// This constructor can be used to front-load string lookups to find exports 1283 /// within a component. 1284 pub fn new<_T>( 1285 _instance_pre: &wasmtime::component::InstancePre<_T>, 1286 ) -> wasmtime::Result<GuestIndices> { 1287 let instance = _instance_pre 1288 .component() 1289 .get_export_index(None, "foo:foo/variants") 1290 .ok_or_else(|| { 1291 wasmtime::format_err!( 1292 "no exported instance named `foo:foo/variants`" 1293 ) 1294 })?; 1295 let mut lookup = move |name| { 1296 _instance_pre 1297 .component() 1298 .get_export_index(Some(&instance), name) 1299 .ok_or_else(|| { 1300 wasmtime::format_err!( 1301 "instance export `foo:foo/variants` does \ 1302 not have export `{name}`" 1303 ) 1304 }) 1305 }; 1306 let _ = &mut lookup; 1307 let e1_arg = lookup("e1-arg")?; 1308 let e1_result = lookup("e1-result")?; 1309 let v1_arg = lookup("v1-arg")?; 1310 let v1_result = lookup("v1-result")?; 1311 let bool_arg = lookup("bool-arg")?; 1312 let bool_result = lookup("bool-result")?; 1313 let option_arg = lookup("option-arg")?; 1314 let option_result = lookup("option-result")?; 1315 let casts = lookup("casts")?; 1316 let result_arg = lookup("result-arg")?; 1317 let result_result = lookup("result-result")?; 1318 let return_result_sugar = lookup("return-result-sugar")?; 1319 let return_result_sugar2 = lookup("return-result-sugar2")?; 1320 let return_result_sugar3 = lookup("return-result-sugar3")?; 1321 let return_result_sugar4 = lookup("return-result-sugar4")?; 1322 let return_option_sugar = lookup("return-option-sugar")?; 1323 let return_option_sugar2 = lookup("return-option-sugar2")?; 1324 let result_simple = lookup("result-simple")?; 1325 let is_clone_arg = lookup("is-clone-arg")?; 1326 let is_clone_return = lookup("is-clone-return")?; 1327 Ok(GuestIndices { 1328 e1_arg, 1329 e1_result, 1330 v1_arg, 1331 v1_result, 1332 bool_arg, 1333 bool_result, 1334 option_arg, 1335 option_result, 1336 casts, 1337 result_arg, 1338 result_result, 1339 return_result_sugar, 1340 return_result_sugar2, 1341 return_result_sugar3, 1342 return_result_sugar4, 1343 return_option_sugar, 1344 return_option_sugar2, 1345 result_simple, 1346 is_clone_arg, 1347 is_clone_return, 1348 }) 1349 } 1350 pub fn load( 1351 &self, 1352 mut store: impl wasmtime::AsContextMut, 1353 instance: &wasmtime::component::Instance, 1354 ) -> wasmtime::Result<Guest> { 1355 let _instance = instance; 1356 let _instance_pre = _instance.instance_pre(&store); 1357 let _instance_type = _instance_pre.instance_type(); 1358 let mut store = store.as_context_mut(); 1359 let _ = &mut store; 1360 let e1_arg = *_instance 1361 .get_typed_func::<(E1,), ()>(&mut store, &self.e1_arg)? 1362 .func(); 1363 let e1_result = *_instance 1364 .get_typed_func::<(), (E1,)>(&mut store, &self.e1_result)? 1365 .func(); 1366 let v1_arg = *_instance 1367 .get_typed_func::<(&V1,), ()>(&mut store, &self.v1_arg)? 1368 .func(); 1369 let v1_result = *_instance 1370 .get_typed_func::<(), (V1,)>(&mut store, &self.v1_result)? 1371 .func(); 1372 let bool_arg = *_instance 1373 .get_typed_func::<(bool,), ()>(&mut store, &self.bool_arg)? 1374 .func(); 1375 let bool_result = *_instance 1376 .get_typed_func::< 1377 (), 1378 (bool,), 1379 >(&mut store, &self.bool_result)? 1380 .func(); 1381 let option_arg = *_instance 1382 .get_typed_func::< 1383 ( 1384 Option<bool>, 1385 Option<()>, 1386 Option<u32>, 1387 Option<E1>, 1388 Option<f32>, 1389 Option<Option<bool>>, 1390 ), 1391 (), 1392 >(&mut store, &self.option_arg)? 1393 .func(); 1394 let option_result = *_instance 1395 .get_typed_func::< 1396 (), 1397 ( 1398 ( 1399 Option<bool>, 1400 Option<()>, 1401 Option<u32>, 1402 Option<E1>, 1403 Option<f32>, 1404 Option<Option<bool>>, 1405 ), 1406 ), 1407 >(&mut store, &self.option_result)? 1408 .func(); 1409 let casts = *_instance 1410 .get_typed_func::< 1411 (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), 1412 ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), 1413 >(&mut store, &self.casts)? 1414 .func(); 1415 let result_arg = *_instance 1416 .get_typed_func::< 1417 ( 1418 Result<(), ()>, 1419 Result<(), E1>, 1420 Result<E1, ()>, 1421 Result<(), ()>, 1422 Result<u32, &V1>, 1423 Result<&str, &[u8]>, 1424 ), 1425 (), 1426 >(&mut store, &self.result_arg)? 1427 .func(); 1428 let result_result = *_instance 1429 .get_typed_func::< 1430 (), 1431 ( 1432 ( 1433 Result<(), ()>, 1434 Result<(), E1>, 1435 Result<E1, ()>, 1436 Result<(), ()>, 1437 Result<u32, V1>, 1438 Result< 1439 wasmtime::component::__internal::String, 1440 wasmtime::component::__internal::Vec<u8>, 1441 >, 1442 ), 1443 ), 1444 >(&mut store, &self.result_result)? 1445 .func(); 1446 let return_result_sugar = *_instance 1447 .get_typed_func::< 1448 (), 1449 (Result<i32, MyErrno>,), 1450 >(&mut store, &self.return_result_sugar)? 1451 .func(); 1452 let return_result_sugar2 = *_instance 1453 .get_typed_func::< 1454 (), 1455 (Result<(), MyErrno>,), 1456 >(&mut store, &self.return_result_sugar2)? 1457 .func(); 1458 let return_result_sugar3 = *_instance 1459 .get_typed_func::< 1460 (), 1461 (Result<MyErrno, MyErrno>,), 1462 >(&mut store, &self.return_result_sugar3)? 1463 .func(); 1464 let return_result_sugar4 = *_instance 1465 .get_typed_func::< 1466 (), 1467 (Result<(i32, u32), MyErrno>,), 1468 >(&mut store, &self.return_result_sugar4)? 1469 .func(); 1470 let return_option_sugar = *_instance 1471 .get_typed_func::< 1472 (), 1473 (Option<i32>,), 1474 >(&mut store, &self.return_option_sugar)? 1475 .func(); 1476 let return_option_sugar2 = *_instance 1477 .get_typed_func::< 1478 (), 1479 (Option<MyErrno>,), 1480 >(&mut store, &self.return_option_sugar2)? 1481 .func(); 1482 let result_simple = *_instance 1483 .get_typed_func::< 1484 (), 1485 (Result<u32, i32>,), 1486 >(&mut store, &self.result_simple)? 1487 .func(); 1488 let is_clone_arg = *_instance 1489 .get_typed_func::< 1490 (&IsClone,), 1491 (), 1492 >(&mut store, &self.is_clone_arg)? 1493 .func(); 1494 let is_clone_return = *_instance 1495 .get_typed_func::< 1496 (), 1497 (IsClone,), 1498 >(&mut store, &self.is_clone_return)? 1499 .func(); 1500 Ok(Guest { 1501 e1_arg, 1502 e1_result, 1503 v1_arg, 1504 v1_result, 1505 bool_arg, 1506 bool_result, 1507 option_arg, 1508 option_result, 1509 casts, 1510 result_arg, 1511 result_result, 1512 return_result_sugar, 1513 return_result_sugar2, 1514 return_result_sugar3, 1515 return_result_sugar4, 1516 return_option_sugar, 1517 return_option_sugar2, 1518 result_simple, 1519 is_clone_arg, 1520 is_clone_return, 1521 }) 1522 } 1523 } 1524 impl Guest { 1525 pub async fn call_e1_arg<_T, _D>( 1526 &self, 1527 accessor: &wasmtime::component::Accessor<_T, _D>, 1528 arg0: E1, 1529 ) -> wasmtime::Result<()> 1530 where 1531 _T: Send, 1532 _D: wasmtime::component::HasData, 1533 { 1534 let callee = unsafe { 1535 wasmtime::component::TypedFunc::< 1536 (E1,), 1537 (), 1538 >::new_unchecked(self.e1_arg) 1539 }; 1540 let ((), _) = callee.call_concurrent(accessor, (arg0,)).await?; 1541 Ok(()) 1542 } 1543 pub async fn call_e1_result<_T, _D>( 1544 &self, 1545 accessor: &wasmtime::component::Accessor<_T, _D>, 1546 ) -> wasmtime::Result<E1> 1547 where 1548 _T: Send, 1549 _D: wasmtime::component::HasData, 1550 { 1551 let callee = unsafe { 1552 wasmtime::component::TypedFunc::< 1553 (), 1554 (E1,), 1555 >::new_unchecked(self.e1_result) 1556 }; 1557 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1558 Ok(ret0) 1559 } 1560 pub async fn call_v1_arg<_T, _D>( 1561 &self, 1562 accessor: &wasmtime::component::Accessor<_T, _D>, 1563 arg0: V1, 1564 ) -> wasmtime::Result<()> 1565 where 1566 _T: Send, 1567 _D: wasmtime::component::HasData, 1568 { 1569 let callee = unsafe { 1570 wasmtime::component::TypedFunc::< 1571 (V1,), 1572 (), 1573 >::new_unchecked(self.v1_arg) 1574 }; 1575 let ((), _) = callee.call_concurrent(accessor, (arg0,)).await?; 1576 Ok(()) 1577 } 1578 pub async fn call_v1_result<_T, _D>( 1579 &self, 1580 accessor: &wasmtime::component::Accessor<_T, _D>, 1581 ) -> wasmtime::Result<V1> 1582 where 1583 _T: Send, 1584 _D: wasmtime::component::HasData, 1585 { 1586 let callee = unsafe { 1587 wasmtime::component::TypedFunc::< 1588 (), 1589 (V1,), 1590 >::new_unchecked(self.v1_result) 1591 }; 1592 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1593 Ok(ret0) 1594 } 1595 pub async fn call_bool_arg<_T, _D>( 1596 &self, 1597 accessor: &wasmtime::component::Accessor<_T, _D>, 1598 arg0: bool, 1599 ) -> wasmtime::Result<()> 1600 where 1601 _T: Send, 1602 _D: wasmtime::component::HasData, 1603 { 1604 let callee = unsafe { 1605 wasmtime::component::TypedFunc::< 1606 (bool,), 1607 (), 1608 >::new_unchecked(self.bool_arg) 1609 }; 1610 let ((), _) = callee.call_concurrent(accessor, (arg0,)).await?; 1611 Ok(()) 1612 } 1613 pub async fn call_bool_result<_T, _D>( 1614 &self, 1615 accessor: &wasmtime::component::Accessor<_T, _D>, 1616 ) -> wasmtime::Result<bool> 1617 where 1618 _T: Send, 1619 _D: wasmtime::component::HasData, 1620 { 1621 let callee = unsafe { 1622 wasmtime::component::TypedFunc::< 1623 (), 1624 (bool,), 1625 >::new_unchecked(self.bool_result) 1626 }; 1627 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1628 Ok(ret0) 1629 } 1630 pub async fn call_option_arg<_T, _D>( 1631 &self, 1632 accessor: &wasmtime::component::Accessor<_T, _D>, 1633 arg0: Option<bool>, 1634 arg1: Option<()>, 1635 arg2: Option<u32>, 1636 arg3: Option<E1>, 1637 arg4: Option<f32>, 1638 arg5: Option<Option<bool>>, 1639 ) -> wasmtime::Result<()> 1640 where 1641 _T: Send, 1642 _D: wasmtime::component::HasData, 1643 { 1644 let callee = unsafe { 1645 wasmtime::component::TypedFunc::< 1646 ( 1647 Option<bool>, 1648 Option<()>, 1649 Option<u32>, 1650 Option<E1>, 1651 Option<f32>, 1652 Option<Option<bool>>, 1653 ), 1654 (), 1655 >::new_unchecked(self.option_arg) 1656 }; 1657 let ((), _) = callee 1658 .call_concurrent( 1659 accessor, 1660 (arg0, arg1, arg2, arg3, arg4, arg5), 1661 ) 1662 .await?; 1663 Ok(()) 1664 } 1665 pub async fn call_option_result<_T, _D>( 1666 &self, 1667 accessor: &wasmtime::component::Accessor<_T, _D>, 1668 ) -> wasmtime::Result< 1669 ( 1670 Option<bool>, 1671 Option<()>, 1672 Option<u32>, 1673 Option<E1>, 1674 Option<f32>, 1675 Option<Option<bool>>, 1676 ), 1677 > 1678 where 1679 _T: Send, 1680 _D: wasmtime::component::HasData, 1681 { 1682 let callee = unsafe { 1683 wasmtime::component::TypedFunc::< 1684 (), 1685 ( 1686 ( 1687 Option<bool>, 1688 Option<()>, 1689 Option<u32>, 1690 Option<E1>, 1691 Option<f32>, 1692 Option<Option<bool>>, 1693 ), 1694 ), 1695 >::new_unchecked(self.option_result) 1696 }; 1697 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1698 Ok(ret0) 1699 } 1700 pub async fn call_casts<_T, _D>( 1701 &self, 1702 accessor: &wasmtime::component::Accessor<_T, _D>, 1703 arg0: Casts1, 1704 arg1: Casts2, 1705 arg2: Casts3, 1706 arg3: Casts4, 1707 arg4: Casts5, 1708 arg5: Casts6, 1709 ) -> wasmtime::Result< 1710 (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), 1711 > 1712 where 1713 _T: Send, 1714 _D: wasmtime::component::HasData, 1715 { 1716 let callee = unsafe { 1717 wasmtime::component::TypedFunc::< 1718 (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), 1719 ((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),), 1720 >::new_unchecked(self.casts) 1721 }; 1722 let ((ret0,), _) = callee 1723 .call_concurrent( 1724 accessor, 1725 (arg0, arg1, arg2, arg3, arg4, arg5), 1726 ) 1727 .await?; 1728 Ok(ret0) 1729 } 1730 pub async fn call_result_arg<_T, _D>( 1731 &self, 1732 accessor: &wasmtime::component::Accessor<_T, _D>, 1733 arg0: Result<(), ()>, 1734 arg1: Result<(), E1>, 1735 arg2: Result<E1, ()>, 1736 arg3: Result<(), ()>, 1737 arg4: Result<u32, V1>, 1738 arg5: Result< 1739 wasmtime::component::__internal::String, 1740 wasmtime::component::__internal::Vec<u8>, 1741 >, 1742 ) -> wasmtime::Result<()> 1743 where 1744 _T: Send, 1745 _D: wasmtime::component::HasData, 1746 { 1747 let callee = unsafe { 1748 wasmtime::component::TypedFunc::< 1749 ( 1750 Result<(), ()>, 1751 Result<(), E1>, 1752 Result<E1, ()>, 1753 Result<(), ()>, 1754 Result<u32, V1>, 1755 Result< 1756 wasmtime::component::__internal::String, 1757 wasmtime::component::__internal::Vec<u8>, 1758 >, 1759 ), 1760 (), 1761 >::new_unchecked(self.result_arg) 1762 }; 1763 let ((), _) = callee 1764 .call_concurrent( 1765 accessor, 1766 (arg0, arg1, arg2, arg3, arg4, arg5), 1767 ) 1768 .await?; 1769 Ok(()) 1770 } 1771 pub async fn call_result_result<_T, _D>( 1772 &self, 1773 accessor: &wasmtime::component::Accessor<_T, _D>, 1774 ) -> wasmtime::Result< 1775 ( 1776 Result<(), ()>, 1777 Result<(), E1>, 1778 Result<E1, ()>, 1779 Result<(), ()>, 1780 Result<u32, V1>, 1781 Result< 1782 wasmtime::component::__internal::String, 1783 wasmtime::component::__internal::Vec<u8>, 1784 >, 1785 ), 1786 > 1787 where 1788 _T: Send, 1789 _D: wasmtime::component::HasData, 1790 { 1791 let callee = unsafe { 1792 wasmtime::component::TypedFunc::< 1793 (), 1794 ( 1795 ( 1796 Result<(), ()>, 1797 Result<(), E1>, 1798 Result<E1, ()>, 1799 Result<(), ()>, 1800 Result<u32, V1>, 1801 Result< 1802 wasmtime::component::__internal::String, 1803 wasmtime::component::__internal::Vec<u8>, 1804 >, 1805 ), 1806 ), 1807 >::new_unchecked(self.result_result) 1808 }; 1809 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1810 Ok(ret0) 1811 } 1812 pub async fn call_return_result_sugar<_T, _D>( 1813 &self, 1814 accessor: &wasmtime::component::Accessor<_T, _D>, 1815 ) -> wasmtime::Result<Result<i32, MyErrno>> 1816 where 1817 _T: Send, 1818 _D: wasmtime::component::HasData, 1819 { 1820 let callee = unsafe { 1821 wasmtime::component::TypedFunc::< 1822 (), 1823 (Result<i32, MyErrno>,), 1824 >::new_unchecked(self.return_result_sugar) 1825 }; 1826 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1827 Ok(ret0) 1828 } 1829 pub async fn call_return_result_sugar2<_T, _D>( 1830 &self, 1831 accessor: &wasmtime::component::Accessor<_T, _D>, 1832 ) -> wasmtime::Result<Result<(), MyErrno>> 1833 where 1834 _T: Send, 1835 _D: wasmtime::component::HasData, 1836 { 1837 let callee = unsafe { 1838 wasmtime::component::TypedFunc::< 1839 (), 1840 (Result<(), MyErrno>,), 1841 >::new_unchecked(self.return_result_sugar2) 1842 }; 1843 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1844 Ok(ret0) 1845 } 1846 pub async fn call_return_result_sugar3<_T, _D>( 1847 &self, 1848 accessor: &wasmtime::component::Accessor<_T, _D>, 1849 ) -> wasmtime::Result<Result<MyErrno, MyErrno>> 1850 where 1851 _T: Send, 1852 _D: wasmtime::component::HasData, 1853 { 1854 let callee = unsafe { 1855 wasmtime::component::TypedFunc::< 1856 (), 1857 (Result<MyErrno, MyErrno>,), 1858 >::new_unchecked(self.return_result_sugar3) 1859 }; 1860 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1861 Ok(ret0) 1862 } 1863 pub async fn call_return_result_sugar4<_T, _D>( 1864 &self, 1865 accessor: &wasmtime::component::Accessor<_T, _D>, 1866 ) -> wasmtime::Result<Result<(i32, u32), MyErrno>> 1867 where 1868 _T: Send, 1869 _D: wasmtime::component::HasData, 1870 { 1871 let callee = unsafe { 1872 wasmtime::component::TypedFunc::< 1873 (), 1874 (Result<(i32, u32), MyErrno>,), 1875 >::new_unchecked(self.return_result_sugar4) 1876 }; 1877 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1878 Ok(ret0) 1879 } 1880 pub async fn call_return_option_sugar<_T, _D>( 1881 &self, 1882 accessor: &wasmtime::component::Accessor<_T, _D>, 1883 ) -> wasmtime::Result<Option<i32>> 1884 where 1885 _T: Send, 1886 _D: wasmtime::component::HasData, 1887 { 1888 let callee = unsafe { 1889 wasmtime::component::TypedFunc::< 1890 (), 1891 (Option<i32>,), 1892 >::new_unchecked(self.return_option_sugar) 1893 }; 1894 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1895 Ok(ret0) 1896 } 1897 pub async fn call_return_option_sugar2<_T, _D>( 1898 &self, 1899 accessor: &wasmtime::component::Accessor<_T, _D>, 1900 ) -> wasmtime::Result<Option<MyErrno>> 1901 where 1902 _T: Send, 1903 _D: wasmtime::component::HasData, 1904 { 1905 let callee = unsafe { 1906 wasmtime::component::TypedFunc::< 1907 (), 1908 (Option<MyErrno>,), 1909 >::new_unchecked(self.return_option_sugar2) 1910 }; 1911 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1912 Ok(ret0) 1913 } 1914 pub async fn call_result_simple<_T, _D>( 1915 &self, 1916 accessor: &wasmtime::component::Accessor<_T, _D>, 1917 ) -> wasmtime::Result<Result<u32, i32>> 1918 where 1919 _T: Send, 1920 _D: wasmtime::component::HasData, 1921 { 1922 let callee = unsafe { 1923 wasmtime::component::TypedFunc::< 1924 (), 1925 (Result<u32, i32>,), 1926 >::new_unchecked(self.result_simple) 1927 }; 1928 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1929 Ok(ret0) 1930 } 1931 pub async fn call_is_clone_arg<_T, _D>( 1932 &self, 1933 accessor: &wasmtime::component::Accessor<_T, _D>, 1934 arg0: IsClone, 1935 ) -> wasmtime::Result<()> 1936 where 1937 _T: Send, 1938 _D: wasmtime::component::HasData, 1939 { 1940 let callee = unsafe { 1941 wasmtime::component::TypedFunc::< 1942 (IsClone,), 1943 (), 1944 >::new_unchecked(self.is_clone_arg) 1945 }; 1946 let ((), _) = callee.call_concurrent(accessor, (arg0,)).await?; 1947 Ok(()) 1948 } 1949 pub async fn call_is_clone_return<_T, _D>( 1950 &self, 1951 accessor: &wasmtime::component::Accessor<_T, _D>, 1952 ) -> wasmtime::Result<IsClone> 1953 where 1954 _T: Send, 1955 _D: wasmtime::component::HasData, 1956 { 1957 let callee = unsafe { 1958 wasmtime::component::TypedFunc::< 1959 (), 1960 (IsClone,), 1961 >::new_unchecked(self.is_clone_return) 1962 }; 1963 let ((ret0,), _) = callee.call_concurrent(accessor, ()).await?; 1964 Ok(ret0) 1965 } 1966 } 1967 } 1968 } 1969 } 1970 } 1971