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