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