1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// component which implements the world `w`. 3 /// 4 /// This structure is created through [`WPre::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 [`W`] as well. 9 pub struct WPre<T: 'static> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: WIndices, 12 } 13 impl<T: 'static> Clone for WPre<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> WPre<_T> { 22 /// Creates a new copy of `WPre` 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 = WIndices::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 [`W`] 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<W> { 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> WPre<_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<W> { 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 /// `w`. 68 /// 69 /// This is an implementation detail of [`WPre`] and can 70 /// be constructed if needed as well. 71 /// 72 /// For more information see [`W`] as well. 73 #[derive(Clone)] 74 pub struct WIndices { 75 interface0: exports::foo::foo::simple_export::GuestIndices, 76 interface1: exports::foo::foo::export_using_import::GuestIndices, 77 interface2: exports::foo::foo::export_using_export1::GuestIndices, 78 interface3: exports::foo::foo::export_using_export2::GuestIndices, 79 } 80 /// Auto-generated bindings for an instance a component which 81 /// implements the world `w`. 82 /// 83 /// This structure can be created through a number of means 84 /// depending on your requirements and what you have on hand: 85 /// 86 /// * The most convenient way is to use 87 /// [`W::instantiate`] which only needs a 88 /// [`Store`], [`Component`], and [`Linker`]. 89 /// 90 /// * Alternatively you can create a [`WPre`] ahead of 91 /// time with a [`Component`] to front-load string lookups 92 /// of exports once instead of per-instantiation. This 93 /// method then uses [`WPre::instantiate`] to 94 /// create a [`W`]. 95 /// 96 /// * If you've instantiated the instance yourself already 97 /// then you can use [`W::new`]. 98 /// 99 /// These methods are all equivalent to one another and move 100 /// around the tradeoff of what work is performed when. 101 /// 102 /// [`Store`]: wasmtime::Store 103 /// [`Component`]: wasmtime::component::Component 104 /// [`Linker`]: wasmtime::component::Linker 105 pub struct W { 106 interface0: exports::foo::foo::simple_export::Guest, 107 interface1: exports::foo::foo::export_using_import::Guest, 108 interface2: exports::foo::foo::export_using_export1::Guest, 109 interface3: exports::foo::foo::export_using_export2::Guest, 110 } 111 const _: () = { 112 impl WIndices { 113 /// Creates a new copy of `WIndices` bindings which can then 114 /// be used to instantiate into a particular store. 115 /// 116 /// This method may fail if the component does not have the 117 /// required exports. 118 pub fn new<_T>( 119 _instance_pre: &wasmtime::component::InstancePre<_T>, 120 ) -> wasmtime::Result<Self> { 121 let _component = _instance_pre.component(); 122 let _instance_type = _instance_pre.instance_type(); 123 let interface0 = exports::foo::foo::simple_export::GuestIndices::new( 124 _instance_pre, 125 )?; 126 let interface1 = exports::foo::foo::export_using_import::GuestIndices::new( 127 _instance_pre, 128 )?; 129 let interface2 = exports::foo::foo::export_using_export1::GuestIndices::new( 130 _instance_pre, 131 )?; 132 let interface3 = exports::foo::foo::export_using_export2::GuestIndices::new( 133 _instance_pre, 134 )?; 135 Ok(WIndices { 136 interface0, 137 interface1, 138 interface2, 139 interface3, 140 }) 141 } 142 /// Uses the indices stored in `self` to load an instance 143 /// of [`W`] from the instance provided. 144 /// 145 /// Note that at this time this method will additionally 146 /// perform type-checks of all exports. 147 pub fn load( 148 &self, 149 mut store: impl wasmtime::AsContextMut, 150 instance: &wasmtime::component::Instance, 151 ) -> wasmtime::Result<W> { 152 let _ = &mut store; 153 let _instance = instance; 154 let interface0 = self.interface0.load(&mut store, &_instance)?; 155 let interface1 = self.interface1.load(&mut store, &_instance)?; 156 let interface2 = self.interface2.load(&mut store, &_instance)?; 157 let interface3 = self.interface3.load(&mut store, &_instance)?; 158 Ok(W { 159 interface0, 160 interface1, 161 interface2, 162 interface3, 163 }) 164 } 165 } 166 impl W { 167 /// Convenience wrapper around [`WPre::new`] and 168 /// [`WPre::instantiate`]. 169 pub fn instantiate<_T>( 170 store: impl wasmtime::AsContextMut<Data = _T>, 171 component: &wasmtime::component::Component, 172 linker: &wasmtime::component::Linker<_T>, 173 ) -> wasmtime::Result<W> { 174 let pre = linker.instantiate_pre(component)?; 175 WPre::new(pre)?.instantiate(store) 176 } 177 /// Convenience wrapper around [`WIndices::new`] and 178 /// [`WIndices::load`]. 179 pub fn new( 180 mut store: impl wasmtime::AsContextMut, 181 instance: &wasmtime::component::Instance, 182 ) -> wasmtime::Result<W> { 183 let indices = WIndices::new(&instance.instance_pre(&store))?; 184 indices.load(&mut store, instance) 185 } 186 /// Convenience wrapper around [`WPre::new`] and 187 /// [`WPre::instantiate_async`]. 188 pub async fn instantiate_async<_T>( 189 store: impl wasmtime::AsContextMut<Data = _T>, 190 component: &wasmtime::component::Component, 191 linker: &wasmtime::component::Linker<_T>, 192 ) -> wasmtime::Result<W> 193 where 194 _T: Send, 195 { 196 let pre = linker.instantiate_pre(component)?; 197 WPre::new(pre)?.instantiate_async(store).await 198 } 199 pub fn add_to_linker<T, D>( 200 linker: &mut wasmtime::component::Linker<T>, 201 host_getter: fn(&mut T) -> D::Data<'_>, 202 ) -> wasmtime::Result<()> 203 where 204 D: foo::foo::transitive_import::HostWithStore + Send, 205 for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send, 206 T: 'static + Send, 207 { 208 foo::foo::transitive_import::add_to_linker::<T, D>(linker, host_getter)?; 209 Ok(()) 210 } 211 pub fn foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest { 212 &self.interface0 213 } 214 pub fn foo_foo_export_using_import( 215 &self, 216 ) -> &exports::foo::foo::export_using_import::Guest { 217 &self.interface1 218 } 219 pub fn foo_foo_export_using_export1( 220 &self, 221 ) -> &exports::foo::foo::export_using_export1::Guest { 222 &self.interface2 223 } 224 pub fn foo_foo_export_using_export2( 225 &self, 226 ) -> &exports::foo::foo::export_using_export2::Guest { 227 &self.interface3 228 } 229 } 230 }; 231 pub mod foo { 232 pub mod foo { 233 #[allow(clippy::all)] 234 pub mod transitive_import { 235 #[allow(unused_imports)] 236 use wasmtime::component::__internal::Box; 237 pub enum Y {} 238 pub trait HostYWithStore: wasmtime::component::HasData {} 239 impl<_T: ?Sized> HostYWithStore for _T 240 where 241 _T: wasmtime::component::HasData, 242 {} 243 pub trait HostY { 244 fn drop( 245 &mut self, 246 rep: wasmtime::component::Resource<Y>, 247 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 248 } 249 impl<_T: HostY + ?Sized + Send> HostY for &mut _T { 250 async fn drop( 251 &mut self, 252 rep: wasmtime::component::Resource<Y>, 253 ) -> wasmtime::Result<()> { 254 HostY::drop(*self, rep).await 255 } 256 } 257 pub trait HostWithStore: wasmtime::component::HasData + HostYWithStore + Send {} 258 impl<_T: ?Sized> HostWithStore for _T 259 where 260 _T: wasmtime::component::HasData + HostYWithStore + Send, 261 {} 262 pub trait Host: HostY + Send {} 263 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 264 pub fn add_to_linker<T, D>( 265 linker: &mut wasmtime::component::Linker<T>, 266 host_getter: fn(&mut T) -> D::Data<'_>, 267 ) -> wasmtime::Result<()> 268 where 269 D: HostWithStore, 270 for<'a> D::Data<'a>: Host, 271 T: 'static + Send, 272 { 273 let mut inst = linker.instance("foo:foo/transitive-import")?; 274 inst.resource_async( 275 "y", 276 wasmtime::component::ResourceType::host::<Y>(), 277 move |mut store, rep| { 278 wasmtime::component::__internal::Box::new(async move { 279 HostY::drop( 280 &mut host_getter(store.data_mut()), 281 wasmtime::component::Resource::new_own(rep), 282 ) 283 .await 284 }) 285 }, 286 )?; 287 Ok(()) 288 } 289 } 290 } 291 } 292 pub mod exports { 293 pub mod foo { 294 pub mod foo { 295 #[allow(clippy::all)] 296 pub mod simple_export { 297 #[allow(unused_imports)] 298 use wasmtime::component::__internal::Box; 299 pub type A = wasmtime::component::ResourceAny; 300 pub struct GuestA<'a> { 301 funcs: &'a Guest, 302 } 303 #[derive(Clone)] 304 pub struct Guest { 305 constructor_a_constructor: wasmtime::component::Func, 306 static_a_static_a: wasmtime::component::Func, 307 method_a_method_a: wasmtime::component::Func, 308 } 309 #[derive(Clone)] 310 pub struct GuestIndices { 311 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 312 static_a_static_a: wasmtime::component::ComponentExportIndex, 313 method_a_method_a: wasmtime::component::ComponentExportIndex, 314 } 315 impl GuestIndices { 316 /// Constructor for [`GuestIndices`] which takes a 317 /// [`Component`](wasmtime::component::Component) as input and can be executed 318 /// before instantiation. 319 /// 320 /// This constructor can be used to front-load string lookups to find exports 321 /// within a component. 322 pub fn new<_T>( 323 _instance_pre: &wasmtime::component::InstancePre<_T>, 324 ) -> wasmtime::Result<GuestIndices> { 325 let instance = _instance_pre 326 .component() 327 .get_export_index(None, "foo:foo/simple-export") 328 .ok_or_else(|| { 329 wasmtime::format_err!( 330 "no exported instance named `foo:foo/simple-export`" 331 ) 332 })?; 333 let mut lookup = move |name| { 334 _instance_pre 335 .component() 336 .get_export_index(Some(&instance), name) 337 .ok_or_else(|| { 338 wasmtime::format_err!( 339 "instance export `foo:foo/simple-export` does \ 340 not have export `{name}`" 341 ) 342 }) 343 }; 344 let _ = &mut lookup; 345 let constructor_a_constructor = lookup("[constructor]a")?; 346 let static_a_static_a = lookup("[static]a.static-a")?; 347 let method_a_method_a = lookup("[method]a.method-a")?; 348 Ok(GuestIndices { 349 constructor_a_constructor, 350 static_a_static_a, 351 method_a_method_a, 352 }) 353 } 354 pub fn load( 355 &self, 356 mut store: impl wasmtime::AsContextMut, 357 instance: &wasmtime::component::Instance, 358 ) -> wasmtime::Result<Guest> { 359 let _instance = instance; 360 let _instance_pre = _instance.instance_pre(&store); 361 let _instance_type = _instance_pre.instance_type(); 362 let mut store = store.as_context_mut(); 363 let _ = &mut store; 364 let constructor_a_constructor = *_instance 365 .get_typed_func::< 366 (), 367 (wasmtime::component::ResourceAny,), 368 >(&mut store, &self.constructor_a_constructor)? 369 .func(); 370 let static_a_static_a = *_instance 371 .get_typed_func::< 372 (), 373 (u32,), 374 >(&mut store, &self.static_a_static_a)? 375 .func(); 376 let method_a_method_a = *_instance 377 .get_typed_func::< 378 (wasmtime::component::ResourceAny,), 379 (u32,), 380 >(&mut store, &self.method_a_method_a)? 381 .func(); 382 Ok(Guest { 383 constructor_a_constructor, 384 static_a_static_a, 385 method_a_method_a, 386 }) 387 } 388 } 389 impl Guest { 390 pub fn a(&self) -> GuestA<'_> { 391 GuestA { funcs: self } 392 } 393 } 394 impl GuestA<'_> { 395 pub async fn call_constructor<S: wasmtime::AsContextMut>( 396 &self, 397 mut store: S, 398 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 399 where 400 <S as wasmtime::AsContext>::Data: Send, 401 { 402 let callee = unsafe { 403 wasmtime::component::TypedFunc::< 404 (), 405 (wasmtime::component::ResourceAny,), 406 >::new_unchecked(self.funcs.constructor_a_constructor) 407 }; 408 let (ret0,) = callee 409 .call_async(store.as_context_mut(), ()) 410 .await?; 411 Ok(ret0) 412 } 413 pub async fn call_static_a<S: wasmtime::AsContextMut>( 414 &self, 415 mut store: S, 416 ) -> wasmtime::Result<u32> 417 where 418 <S as wasmtime::AsContext>::Data: Send, 419 { 420 let callee = unsafe { 421 wasmtime::component::TypedFunc::< 422 (), 423 (u32,), 424 >::new_unchecked(self.funcs.static_a_static_a) 425 }; 426 let (ret0,) = callee 427 .call_async(store.as_context_mut(), ()) 428 .await?; 429 Ok(ret0) 430 } 431 pub async fn call_method_a<S: wasmtime::AsContextMut>( 432 &self, 433 mut store: S, 434 arg0: wasmtime::component::ResourceAny, 435 ) -> wasmtime::Result<u32> 436 where 437 <S as wasmtime::AsContext>::Data: Send, 438 { 439 let callee = unsafe { 440 wasmtime::component::TypedFunc::< 441 (wasmtime::component::ResourceAny,), 442 (u32,), 443 >::new_unchecked(self.funcs.method_a_method_a) 444 }; 445 let (ret0,) = callee 446 .call_async(store.as_context_mut(), (arg0,)) 447 .await?; 448 Ok(ret0) 449 } 450 } 451 } 452 #[allow(clippy::all)] 453 pub mod export_using_import { 454 #[allow(unused_imports)] 455 use wasmtime::component::__internal::Box; 456 pub type Y = super::super::super::super::foo::foo::transitive_import::Y; 457 pub type A = wasmtime::component::ResourceAny; 458 pub struct GuestA<'a> { 459 funcs: &'a Guest, 460 } 461 #[derive(Clone)] 462 pub struct Guest { 463 constructor_a_constructor: wasmtime::component::Func, 464 static_a_static_a: wasmtime::component::Func, 465 method_a_method_a: wasmtime::component::Func, 466 } 467 #[derive(Clone)] 468 pub struct GuestIndices { 469 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 470 static_a_static_a: wasmtime::component::ComponentExportIndex, 471 method_a_method_a: wasmtime::component::ComponentExportIndex, 472 } 473 impl GuestIndices { 474 /// Constructor for [`GuestIndices`] which takes a 475 /// [`Component`](wasmtime::component::Component) as input and can be executed 476 /// before instantiation. 477 /// 478 /// This constructor can be used to front-load string lookups to find exports 479 /// within a component. 480 pub fn new<_T>( 481 _instance_pre: &wasmtime::component::InstancePre<_T>, 482 ) -> wasmtime::Result<GuestIndices> { 483 let instance = _instance_pre 484 .component() 485 .get_export_index(None, "foo:foo/export-using-import") 486 .ok_or_else(|| { 487 wasmtime::format_err!( 488 "no exported instance named `foo:foo/export-using-import`" 489 ) 490 })?; 491 let mut lookup = move |name| { 492 _instance_pre 493 .component() 494 .get_export_index(Some(&instance), name) 495 .ok_or_else(|| { 496 wasmtime::format_err!( 497 "instance export `foo:foo/export-using-import` does \ 498 not have export `{name}`" 499 ) 500 }) 501 }; 502 let _ = &mut lookup; 503 let constructor_a_constructor = lookup("[constructor]a")?; 504 let static_a_static_a = lookup("[static]a.static-a")?; 505 let method_a_method_a = lookup("[method]a.method-a")?; 506 Ok(GuestIndices { 507 constructor_a_constructor, 508 static_a_static_a, 509 method_a_method_a, 510 }) 511 } 512 pub fn load( 513 &self, 514 mut store: impl wasmtime::AsContextMut, 515 instance: &wasmtime::component::Instance, 516 ) -> wasmtime::Result<Guest> { 517 let _instance = instance; 518 let _instance_pre = _instance.instance_pre(&store); 519 let _instance_type = _instance_pre.instance_type(); 520 let mut store = store.as_context_mut(); 521 let _ = &mut store; 522 let constructor_a_constructor = *_instance 523 .get_typed_func::< 524 (wasmtime::component::Resource<Y>,), 525 (wasmtime::component::ResourceAny,), 526 >(&mut store, &self.constructor_a_constructor)? 527 .func(); 528 let static_a_static_a = *_instance 529 .get_typed_func::< 530 (), 531 (wasmtime::component::Resource<Y>,), 532 >(&mut store, &self.static_a_static_a)? 533 .func(); 534 let method_a_method_a = *_instance 535 .get_typed_func::< 536 ( 537 wasmtime::component::ResourceAny, 538 wasmtime::component::Resource<Y>, 539 ), 540 (wasmtime::component::Resource<Y>,), 541 >(&mut store, &self.method_a_method_a)? 542 .func(); 543 Ok(Guest { 544 constructor_a_constructor, 545 static_a_static_a, 546 method_a_method_a, 547 }) 548 } 549 } 550 impl Guest { 551 pub fn a(&self) -> GuestA<'_> { 552 GuestA { funcs: self } 553 } 554 } 555 impl GuestA<'_> { 556 pub async fn call_constructor<S: wasmtime::AsContextMut>( 557 &self, 558 mut store: S, 559 arg0: wasmtime::component::Resource<Y>, 560 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 561 where 562 <S as wasmtime::AsContext>::Data: Send, 563 { 564 let callee = unsafe { 565 wasmtime::component::TypedFunc::< 566 (wasmtime::component::Resource<Y>,), 567 (wasmtime::component::ResourceAny,), 568 >::new_unchecked(self.funcs.constructor_a_constructor) 569 }; 570 let (ret0,) = callee 571 .call_async(store.as_context_mut(), (arg0,)) 572 .await?; 573 Ok(ret0) 574 } 575 pub async fn call_static_a<S: wasmtime::AsContextMut>( 576 &self, 577 mut store: S, 578 ) -> wasmtime::Result<wasmtime::component::Resource<Y>> 579 where 580 <S as wasmtime::AsContext>::Data: Send, 581 { 582 let callee = unsafe { 583 wasmtime::component::TypedFunc::< 584 (), 585 (wasmtime::component::Resource<Y>,), 586 >::new_unchecked(self.funcs.static_a_static_a) 587 }; 588 let (ret0,) = callee 589 .call_async(store.as_context_mut(), ()) 590 .await?; 591 Ok(ret0) 592 } 593 pub async fn call_method_a<S: wasmtime::AsContextMut>( 594 &self, 595 mut store: S, 596 arg0: wasmtime::component::ResourceAny, 597 arg1: wasmtime::component::Resource<Y>, 598 ) -> wasmtime::Result<wasmtime::component::Resource<Y>> 599 where 600 <S as wasmtime::AsContext>::Data: Send, 601 { 602 let callee = unsafe { 603 wasmtime::component::TypedFunc::< 604 ( 605 wasmtime::component::ResourceAny, 606 wasmtime::component::Resource<Y>, 607 ), 608 (wasmtime::component::Resource<Y>,), 609 >::new_unchecked(self.funcs.method_a_method_a) 610 }; 611 let (ret0,) = callee 612 .call_async(store.as_context_mut(), (arg0, arg1)) 613 .await?; 614 Ok(ret0) 615 } 616 } 617 } 618 #[allow(clippy::all)] 619 pub mod export_using_export1 { 620 #[allow(unused_imports)] 621 use wasmtime::component::__internal::Box; 622 pub type A = wasmtime::component::ResourceAny; 623 pub struct GuestA<'a> { 624 funcs: &'a Guest, 625 } 626 #[derive(Clone)] 627 pub struct Guest { 628 constructor_a_constructor: wasmtime::component::Func, 629 } 630 #[derive(Clone)] 631 pub struct GuestIndices { 632 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 633 } 634 impl GuestIndices { 635 /// Constructor for [`GuestIndices`] which takes a 636 /// [`Component`](wasmtime::component::Component) as input and can be executed 637 /// before instantiation. 638 /// 639 /// This constructor can be used to front-load string lookups to find exports 640 /// within a component. 641 pub fn new<_T>( 642 _instance_pre: &wasmtime::component::InstancePre<_T>, 643 ) -> wasmtime::Result<GuestIndices> { 644 let instance = _instance_pre 645 .component() 646 .get_export_index(None, "foo:foo/export-using-export1") 647 .ok_or_else(|| { 648 wasmtime::format_err!( 649 "no exported instance named `foo:foo/export-using-export1`" 650 ) 651 })?; 652 let mut lookup = move |name| { 653 _instance_pre 654 .component() 655 .get_export_index(Some(&instance), name) 656 .ok_or_else(|| { 657 wasmtime::format_err!( 658 "instance export `foo:foo/export-using-export1` does \ 659 not have export `{name}`" 660 ) 661 }) 662 }; 663 let _ = &mut lookup; 664 let constructor_a_constructor = lookup("[constructor]a")?; 665 Ok(GuestIndices { 666 constructor_a_constructor, 667 }) 668 } 669 pub fn load( 670 &self, 671 mut store: impl wasmtime::AsContextMut, 672 instance: &wasmtime::component::Instance, 673 ) -> wasmtime::Result<Guest> { 674 let _instance = instance; 675 let _instance_pre = _instance.instance_pre(&store); 676 let _instance_type = _instance_pre.instance_type(); 677 let mut store = store.as_context_mut(); 678 let _ = &mut store; 679 let constructor_a_constructor = *_instance 680 .get_typed_func::< 681 (), 682 (wasmtime::component::ResourceAny,), 683 >(&mut store, &self.constructor_a_constructor)? 684 .func(); 685 Ok(Guest { constructor_a_constructor }) 686 } 687 } 688 impl Guest { 689 pub fn a(&self) -> GuestA<'_> { 690 GuestA { funcs: self } 691 } 692 } 693 impl GuestA<'_> { 694 pub async fn call_constructor<S: wasmtime::AsContextMut>( 695 &self, 696 mut store: S, 697 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 698 where 699 <S as wasmtime::AsContext>::Data: Send, 700 { 701 let callee = unsafe { 702 wasmtime::component::TypedFunc::< 703 (), 704 (wasmtime::component::ResourceAny,), 705 >::new_unchecked(self.funcs.constructor_a_constructor) 706 }; 707 let (ret0,) = callee 708 .call_async(store.as_context_mut(), ()) 709 .await?; 710 Ok(ret0) 711 } 712 } 713 } 714 #[allow(clippy::all)] 715 pub mod export_using_export2 { 716 #[allow(unused_imports)] 717 use wasmtime::component::__internal::Box; 718 pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A; 719 pub type B = wasmtime::component::ResourceAny; 720 pub struct GuestB<'a> { 721 funcs: &'a Guest, 722 } 723 #[derive(Clone)] 724 pub struct Guest { 725 constructor_b_constructor: wasmtime::component::Func, 726 } 727 #[derive(Clone)] 728 pub struct GuestIndices { 729 constructor_b_constructor: wasmtime::component::ComponentExportIndex, 730 } 731 impl GuestIndices { 732 /// Constructor for [`GuestIndices`] which takes a 733 /// [`Component`](wasmtime::component::Component) as input and can be executed 734 /// before instantiation. 735 /// 736 /// This constructor can be used to front-load string lookups to find exports 737 /// within a component. 738 pub fn new<_T>( 739 _instance_pre: &wasmtime::component::InstancePre<_T>, 740 ) -> wasmtime::Result<GuestIndices> { 741 let instance = _instance_pre 742 .component() 743 .get_export_index(None, "foo:foo/export-using-export2") 744 .ok_or_else(|| { 745 wasmtime::format_err!( 746 "no exported instance named `foo:foo/export-using-export2`" 747 ) 748 })?; 749 let mut lookup = move |name| { 750 _instance_pre 751 .component() 752 .get_export_index(Some(&instance), name) 753 .ok_or_else(|| { 754 wasmtime::format_err!( 755 "instance export `foo:foo/export-using-export2` does \ 756 not have export `{name}`" 757 ) 758 }) 759 }; 760 let _ = &mut lookup; 761 let constructor_b_constructor = lookup("[constructor]b")?; 762 Ok(GuestIndices { 763 constructor_b_constructor, 764 }) 765 } 766 pub fn load( 767 &self, 768 mut store: impl wasmtime::AsContextMut, 769 instance: &wasmtime::component::Instance, 770 ) -> wasmtime::Result<Guest> { 771 let _instance = instance; 772 let _instance_pre = _instance.instance_pre(&store); 773 let _instance_type = _instance_pre.instance_type(); 774 let mut store = store.as_context_mut(); 775 let _ = &mut store; 776 let constructor_b_constructor = *_instance 777 .get_typed_func::< 778 (wasmtime::component::ResourceAny,), 779 (wasmtime::component::ResourceAny,), 780 >(&mut store, &self.constructor_b_constructor)? 781 .func(); 782 Ok(Guest { constructor_b_constructor }) 783 } 784 } 785 impl Guest { 786 pub fn b(&self) -> GuestB<'_> { 787 GuestB { funcs: self } 788 } 789 } 790 impl GuestB<'_> { 791 pub async fn call_constructor<S: wasmtime::AsContextMut>( 792 &self, 793 mut store: S, 794 arg0: wasmtime::component::ResourceAny, 795 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 796 where 797 <S as wasmtime::AsContext>::Data: Send, 798 { 799 let callee = unsafe { 800 wasmtime::component::TypedFunc::< 801 (wasmtime::component::ResourceAny,), 802 (wasmtime::component::ResourceAny,), 803 >::new_unchecked(self.funcs.constructor_b_constructor) 804 }; 805 let (ret0,) = callee 806 .call_async(store.as_context_mut(), (arg0,)) 807 .await?; 808 Ok(ret0) 809 } 810 } 811 } 812 } 813 } 814 } 815