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 fn drop<T: 'static>( 242 accessor: &wasmtime::component::Accessor<T, Self>, 243 rep: wasmtime::component::Resource<Y>, 244 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send 245 where 246 Self: Sized; 247 } 248 pub trait HostY {} 249 impl<_T: HostY + ?Sized + Send> HostY for &mut _T {} 250 pub trait HostWithStore: wasmtime::component::HasData + HostYWithStore + Send {} 251 impl<_T: ?Sized> HostWithStore for _T 252 where 253 _T: wasmtime::component::HasData + HostYWithStore + Send, 254 {} 255 pub trait Host: HostY + Send {} 256 impl<_T: Host + ?Sized + Send> Host for &mut _T {} 257 pub fn add_to_linker<T, D>( 258 linker: &mut wasmtime::component::Linker<T>, 259 host_getter: fn(&mut T) -> D::Data<'_>, 260 ) -> wasmtime::Result<()> 261 where 262 D: HostWithStore, 263 for<'a> D::Data<'a>: Host, 264 T: 'static + Send, 265 { 266 let mut inst = linker.instance("foo:foo/transitive-import")?; 267 inst.resource_concurrent( 268 "y", 269 wasmtime::component::ResourceType::host::<Y>(), 270 move |caller: &wasmtime::component::Accessor<T>, rep| { 271 wasmtime::component::__internal::Box::pin(async move { 272 let accessor = &caller.with_data(host_getter); 273 HostYWithStore::drop( 274 accessor, 275 wasmtime::component::Resource::new_own(rep), 276 ) 277 .await 278 }) 279 }, 280 )?; 281 Ok(()) 282 } 283 } 284 } 285 } 286 pub mod exports { 287 pub mod foo { 288 pub mod foo { 289 #[allow(clippy::all)] 290 pub mod simple_export { 291 #[allow(unused_imports)] 292 use wasmtime::component::__internal::{anyhow, Box}; 293 pub type A = wasmtime::component::ResourceAny; 294 pub struct GuestA<'a> { 295 funcs: &'a Guest, 296 } 297 pub struct Guest { 298 constructor_a_constructor: wasmtime::component::Func, 299 static_a_static_a: wasmtime::component::Func, 300 method_a_method_a: wasmtime::component::Func, 301 } 302 #[derive(Clone)] 303 pub struct GuestIndices { 304 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 305 static_a_static_a: wasmtime::component::ComponentExportIndex, 306 method_a_method_a: wasmtime::component::ComponentExportIndex, 307 } 308 impl GuestIndices { 309 /// Constructor for [`GuestIndices`] which takes a 310 /// [`Component`](wasmtime::component::Component) as input and can be executed 311 /// before instantiation. 312 /// 313 /// This constructor can be used to front-load string lookups to find exports 314 /// within a component. 315 pub fn new<_T>( 316 _instance_pre: &wasmtime::component::InstancePre<_T>, 317 ) -> wasmtime::Result<GuestIndices> { 318 let instance = _instance_pre 319 .component() 320 .get_export_index(None, "foo:foo/simple-export") 321 .ok_or_else(|| { 322 anyhow::anyhow!( 323 "no exported instance named `foo:foo/simple-export`" 324 ) 325 })?; 326 let mut lookup = move |name| { 327 _instance_pre 328 .component() 329 .get_export_index(Some(&instance), name) 330 .ok_or_else(|| { 331 anyhow::anyhow!( 332 "instance export `foo:foo/simple-export` does \ 333 not have export `{name}`" 334 ) 335 }) 336 }; 337 let _ = &mut lookup; 338 let constructor_a_constructor = lookup("[constructor]a")?; 339 let static_a_static_a = lookup("[static]a.static-a")?; 340 let method_a_method_a = lookup("[method]a.method-a")?; 341 Ok(GuestIndices { 342 constructor_a_constructor, 343 static_a_static_a, 344 method_a_method_a, 345 }) 346 } 347 pub fn load( 348 &self, 349 mut store: impl wasmtime::AsContextMut, 350 instance: &wasmtime::component::Instance, 351 ) -> wasmtime::Result<Guest> { 352 let _instance = instance; 353 let _instance_pre = _instance.instance_pre(&store); 354 let _instance_type = _instance_pre.instance_type(); 355 let mut store = store.as_context_mut(); 356 let _ = &mut store; 357 let constructor_a_constructor = *_instance 358 .get_typed_func::< 359 (), 360 (wasmtime::component::ResourceAny,), 361 >(&mut store, &self.constructor_a_constructor)? 362 .func(); 363 let static_a_static_a = *_instance 364 .get_typed_func::< 365 (), 366 (u32,), 367 >(&mut store, &self.static_a_static_a)? 368 .func(); 369 let method_a_method_a = *_instance 370 .get_typed_func::< 371 (wasmtime::component::ResourceAny,), 372 (u32,), 373 >(&mut store, &self.method_a_method_a)? 374 .func(); 375 Ok(Guest { 376 constructor_a_constructor, 377 static_a_static_a, 378 method_a_method_a, 379 }) 380 } 381 } 382 impl Guest { 383 pub fn a(&self) -> GuestA<'_> { 384 GuestA { funcs: self } 385 } 386 } 387 impl GuestA<'_> { 388 pub async fn call_constructor<_T, _D>( 389 &self, 390 accessor: &wasmtime::component::Accessor<_T, _D>, 391 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 392 where 393 _T: Send, 394 _D: wasmtime::component::HasData, 395 { 396 let callee = unsafe { 397 wasmtime::component::TypedFunc::< 398 (), 399 (wasmtime::component::ResourceAny,), 400 >::new_unchecked(self.funcs.constructor_a_constructor) 401 }; 402 let (ret0,) = callee.call_concurrent(accessor, ()).await?; 403 Ok(ret0) 404 } 405 pub async fn call_static_a<_T, _D>( 406 &self, 407 accessor: &wasmtime::component::Accessor<_T, _D>, 408 ) -> wasmtime::Result<u32> 409 where 410 _T: Send, 411 _D: wasmtime::component::HasData, 412 { 413 let callee = unsafe { 414 wasmtime::component::TypedFunc::< 415 (), 416 (u32,), 417 >::new_unchecked(self.funcs.static_a_static_a) 418 }; 419 let (ret0,) = callee.call_concurrent(accessor, ()).await?; 420 Ok(ret0) 421 } 422 pub async fn call_method_a<_T, _D>( 423 &self, 424 accessor: &wasmtime::component::Accessor<_T, _D>, 425 arg0: wasmtime::component::ResourceAny, 426 ) -> wasmtime::Result<u32> 427 where 428 _T: Send, 429 _D: wasmtime::component::HasData, 430 { 431 let callee = unsafe { 432 wasmtime::component::TypedFunc::< 433 (wasmtime::component::ResourceAny,), 434 (u32,), 435 >::new_unchecked(self.funcs.method_a_method_a) 436 }; 437 let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; 438 Ok(ret0) 439 } 440 } 441 } 442 #[allow(clippy::all)] 443 pub mod export_using_import { 444 #[allow(unused_imports)] 445 use wasmtime::component::__internal::{anyhow, Box}; 446 pub type Y = super::super::super::super::foo::foo::transitive_import::Y; 447 pub type A = wasmtime::component::ResourceAny; 448 pub struct GuestA<'a> { 449 funcs: &'a Guest, 450 } 451 pub struct Guest { 452 constructor_a_constructor: wasmtime::component::Func, 453 static_a_static_a: wasmtime::component::Func, 454 method_a_method_a: wasmtime::component::Func, 455 } 456 #[derive(Clone)] 457 pub struct GuestIndices { 458 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 459 static_a_static_a: wasmtime::component::ComponentExportIndex, 460 method_a_method_a: wasmtime::component::ComponentExportIndex, 461 } 462 impl GuestIndices { 463 /// Constructor for [`GuestIndices`] which takes a 464 /// [`Component`](wasmtime::component::Component) as input and can be executed 465 /// before instantiation. 466 /// 467 /// This constructor can be used to front-load string lookups to find exports 468 /// within a component. 469 pub fn new<_T>( 470 _instance_pre: &wasmtime::component::InstancePre<_T>, 471 ) -> wasmtime::Result<GuestIndices> { 472 let instance = _instance_pre 473 .component() 474 .get_export_index(None, "foo:foo/export-using-import") 475 .ok_or_else(|| { 476 anyhow::anyhow!( 477 "no exported instance named `foo:foo/export-using-import`" 478 ) 479 })?; 480 let mut lookup = move |name| { 481 _instance_pre 482 .component() 483 .get_export_index(Some(&instance), name) 484 .ok_or_else(|| { 485 anyhow::anyhow!( 486 "instance export `foo:foo/export-using-import` does \ 487 not have export `{name}`" 488 ) 489 }) 490 }; 491 let _ = &mut lookup; 492 let constructor_a_constructor = lookup("[constructor]a")?; 493 let static_a_static_a = lookup("[static]a.static-a")?; 494 let method_a_method_a = lookup("[method]a.method-a")?; 495 Ok(GuestIndices { 496 constructor_a_constructor, 497 static_a_static_a, 498 method_a_method_a, 499 }) 500 } 501 pub fn load( 502 &self, 503 mut store: impl wasmtime::AsContextMut, 504 instance: &wasmtime::component::Instance, 505 ) -> wasmtime::Result<Guest> { 506 let _instance = instance; 507 let _instance_pre = _instance.instance_pre(&store); 508 let _instance_type = _instance_pre.instance_type(); 509 let mut store = store.as_context_mut(); 510 let _ = &mut store; 511 let constructor_a_constructor = *_instance 512 .get_typed_func::< 513 (wasmtime::component::Resource<Y>,), 514 (wasmtime::component::ResourceAny,), 515 >(&mut store, &self.constructor_a_constructor)? 516 .func(); 517 let static_a_static_a = *_instance 518 .get_typed_func::< 519 (), 520 (wasmtime::component::Resource<Y>,), 521 >(&mut store, &self.static_a_static_a)? 522 .func(); 523 let method_a_method_a = *_instance 524 .get_typed_func::< 525 ( 526 wasmtime::component::ResourceAny, 527 wasmtime::component::Resource<Y>, 528 ), 529 (wasmtime::component::Resource<Y>,), 530 >(&mut store, &self.method_a_method_a)? 531 .func(); 532 Ok(Guest { 533 constructor_a_constructor, 534 static_a_static_a, 535 method_a_method_a, 536 }) 537 } 538 } 539 impl Guest { 540 pub fn a(&self) -> GuestA<'_> { 541 GuestA { funcs: self } 542 } 543 } 544 impl GuestA<'_> { 545 pub async fn call_constructor<_T, _D>( 546 &self, 547 accessor: &wasmtime::component::Accessor<_T, _D>, 548 arg0: wasmtime::component::Resource<Y>, 549 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 550 where 551 _T: Send, 552 _D: wasmtime::component::HasData, 553 { 554 let callee = unsafe { 555 wasmtime::component::TypedFunc::< 556 (wasmtime::component::Resource<Y>,), 557 (wasmtime::component::ResourceAny,), 558 >::new_unchecked(self.funcs.constructor_a_constructor) 559 }; 560 let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; 561 Ok(ret0) 562 } 563 pub async fn call_static_a<_T, _D>( 564 &self, 565 accessor: &wasmtime::component::Accessor<_T, _D>, 566 ) -> wasmtime::Result<wasmtime::component::Resource<Y>> 567 where 568 _T: Send, 569 _D: wasmtime::component::HasData, 570 { 571 let callee = unsafe { 572 wasmtime::component::TypedFunc::< 573 (), 574 (wasmtime::component::Resource<Y>,), 575 >::new_unchecked(self.funcs.static_a_static_a) 576 }; 577 let (ret0,) = callee.call_concurrent(accessor, ()).await?; 578 Ok(ret0) 579 } 580 pub async fn call_method_a<_T, _D>( 581 &self, 582 accessor: &wasmtime::component::Accessor<_T, _D>, 583 arg0: wasmtime::component::ResourceAny, 584 arg1: wasmtime::component::Resource<Y>, 585 ) -> wasmtime::Result<wasmtime::component::Resource<Y>> 586 where 587 _T: Send, 588 _D: wasmtime::component::HasData, 589 { 590 let callee = unsafe { 591 wasmtime::component::TypedFunc::< 592 ( 593 wasmtime::component::ResourceAny, 594 wasmtime::component::Resource<Y>, 595 ), 596 (wasmtime::component::Resource<Y>,), 597 >::new_unchecked(self.funcs.method_a_method_a) 598 }; 599 let (ret0,) = callee 600 .call_concurrent(accessor, (arg0, arg1)) 601 .await?; 602 Ok(ret0) 603 } 604 } 605 } 606 #[allow(clippy::all)] 607 pub mod export_using_export1 { 608 #[allow(unused_imports)] 609 use wasmtime::component::__internal::{anyhow, Box}; 610 pub type A = wasmtime::component::ResourceAny; 611 pub struct GuestA<'a> { 612 funcs: &'a Guest, 613 } 614 pub struct Guest { 615 constructor_a_constructor: wasmtime::component::Func, 616 } 617 #[derive(Clone)] 618 pub struct GuestIndices { 619 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 620 } 621 impl GuestIndices { 622 /// Constructor for [`GuestIndices`] which takes a 623 /// [`Component`](wasmtime::component::Component) as input and can be executed 624 /// before instantiation. 625 /// 626 /// This constructor can be used to front-load string lookups to find exports 627 /// within a component. 628 pub fn new<_T>( 629 _instance_pre: &wasmtime::component::InstancePre<_T>, 630 ) -> wasmtime::Result<GuestIndices> { 631 let instance = _instance_pre 632 .component() 633 .get_export_index(None, "foo:foo/export-using-export1") 634 .ok_or_else(|| { 635 anyhow::anyhow!( 636 "no exported instance named `foo:foo/export-using-export1`" 637 ) 638 })?; 639 let mut lookup = move |name| { 640 _instance_pre 641 .component() 642 .get_export_index(Some(&instance), name) 643 .ok_or_else(|| { 644 anyhow::anyhow!( 645 "instance export `foo:foo/export-using-export1` does \ 646 not have export `{name}`" 647 ) 648 }) 649 }; 650 let _ = &mut lookup; 651 let constructor_a_constructor = lookup("[constructor]a")?; 652 Ok(GuestIndices { 653 constructor_a_constructor, 654 }) 655 } 656 pub fn load( 657 &self, 658 mut store: impl wasmtime::AsContextMut, 659 instance: &wasmtime::component::Instance, 660 ) -> wasmtime::Result<Guest> { 661 let _instance = instance; 662 let _instance_pre = _instance.instance_pre(&store); 663 let _instance_type = _instance_pre.instance_type(); 664 let mut store = store.as_context_mut(); 665 let _ = &mut store; 666 let constructor_a_constructor = *_instance 667 .get_typed_func::< 668 (), 669 (wasmtime::component::ResourceAny,), 670 >(&mut store, &self.constructor_a_constructor)? 671 .func(); 672 Ok(Guest { constructor_a_constructor }) 673 } 674 } 675 impl Guest { 676 pub fn a(&self) -> GuestA<'_> { 677 GuestA { funcs: self } 678 } 679 } 680 impl GuestA<'_> { 681 pub async fn call_constructor<_T, _D>( 682 &self, 683 accessor: &wasmtime::component::Accessor<_T, _D>, 684 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 685 where 686 _T: Send, 687 _D: wasmtime::component::HasData, 688 { 689 let callee = unsafe { 690 wasmtime::component::TypedFunc::< 691 (), 692 (wasmtime::component::ResourceAny,), 693 >::new_unchecked(self.funcs.constructor_a_constructor) 694 }; 695 let (ret0,) = callee.call_concurrent(accessor, ()).await?; 696 Ok(ret0) 697 } 698 } 699 } 700 #[allow(clippy::all)] 701 pub mod export_using_export2 { 702 #[allow(unused_imports)] 703 use wasmtime::component::__internal::{anyhow, Box}; 704 pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A; 705 pub type B = wasmtime::component::ResourceAny; 706 pub struct GuestB<'a> { 707 funcs: &'a Guest, 708 } 709 pub struct Guest { 710 constructor_b_constructor: wasmtime::component::Func, 711 } 712 #[derive(Clone)] 713 pub struct GuestIndices { 714 constructor_b_constructor: wasmtime::component::ComponentExportIndex, 715 } 716 impl GuestIndices { 717 /// Constructor for [`GuestIndices`] which takes a 718 /// [`Component`](wasmtime::component::Component) as input and can be executed 719 /// before instantiation. 720 /// 721 /// This constructor can be used to front-load string lookups to find exports 722 /// within a component. 723 pub fn new<_T>( 724 _instance_pre: &wasmtime::component::InstancePre<_T>, 725 ) -> wasmtime::Result<GuestIndices> { 726 let instance = _instance_pre 727 .component() 728 .get_export_index(None, "foo:foo/export-using-export2") 729 .ok_or_else(|| { 730 anyhow::anyhow!( 731 "no exported instance named `foo:foo/export-using-export2`" 732 ) 733 })?; 734 let mut lookup = move |name| { 735 _instance_pre 736 .component() 737 .get_export_index(Some(&instance), name) 738 .ok_or_else(|| { 739 anyhow::anyhow!( 740 "instance export `foo:foo/export-using-export2` does \ 741 not have export `{name}`" 742 ) 743 }) 744 }; 745 let _ = &mut lookup; 746 let constructor_b_constructor = lookup("[constructor]b")?; 747 Ok(GuestIndices { 748 constructor_b_constructor, 749 }) 750 } 751 pub fn load( 752 &self, 753 mut store: impl wasmtime::AsContextMut, 754 instance: &wasmtime::component::Instance, 755 ) -> wasmtime::Result<Guest> { 756 let _instance = instance; 757 let _instance_pre = _instance.instance_pre(&store); 758 let _instance_type = _instance_pre.instance_type(); 759 let mut store = store.as_context_mut(); 760 let _ = &mut store; 761 let constructor_b_constructor = *_instance 762 .get_typed_func::< 763 (wasmtime::component::ResourceAny,), 764 (wasmtime::component::ResourceAny,), 765 >(&mut store, &self.constructor_b_constructor)? 766 .func(); 767 Ok(Guest { constructor_b_constructor }) 768 } 769 } 770 impl Guest { 771 pub fn b(&self) -> GuestB<'_> { 772 GuestB { funcs: self } 773 } 774 } 775 impl GuestB<'_> { 776 pub async fn call_constructor<_T, _D>( 777 &self, 778 accessor: &wasmtime::component::Accessor<_T, _D>, 779 arg0: wasmtime::component::ResourceAny, 780 ) -> wasmtime::Result<wasmtime::component::ResourceAny> 781 where 782 _T: Send, 783 _D: wasmtime::component::HasData, 784 { 785 let callee = unsafe { 786 wasmtime::component::TypedFunc::< 787 (wasmtime::component::ResourceAny,), 788 (wasmtime::component::ResourceAny,), 789 >::new_unchecked(self.funcs.constructor_b_constructor) 790 }; 791 let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?; 792 Ok(ret0) 793 } 794 } 795 } 796 } 797 } 798 } 799