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> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: WIndices, 12 } 13 impl<T> 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> 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 async fn instantiate_async( 47 &self, 48 mut store: impl wasmtime::AsContextMut<Data = _T>, 49 ) -> wasmtime::Result<W> 50 where 51 _T: Send + 'static, 52 { 53 let mut store = store.as_context_mut(); 54 let instance = self.instance_pre.instantiate_async(&mut store).await?; 55 self.indices.load(&mut store, &instance) 56 } 57 } 58 /// Auto-generated bindings for index of the exports of 59 /// `w`. 60 /// 61 /// This is an implementation detail of [`WPre`] and can 62 /// be constructed if needed as well. 63 /// 64 /// For more information see [`W`] as well. 65 #[derive(Clone)] 66 pub struct WIndices { 67 interface0: exports::foo::foo::simple_export::GuestIndices, 68 interface1: exports::foo::foo::export_using_import::GuestIndices, 69 interface2: exports::foo::foo::export_using_export1::GuestIndices, 70 interface3: exports::foo::foo::export_using_export2::GuestIndices, 71 } 72 /// Auto-generated bindings for an instance a component which 73 /// implements the world `w`. 74 /// 75 /// This structure can be created through a number of means 76 /// depending on your requirements and what you have on hand: 77 /// 78 /// * The most convenient way is to use 79 /// [`W::instantiate_async`] which only needs a 80 /// [`Store`], [`Component`], and [`Linker`]. 81 /// 82 /// * Alternatively you can create a [`WPre`] ahead of 83 /// time with a [`Component`] to front-load string lookups 84 /// of exports once instead of per-instantiation. This 85 /// method then uses [`WPre::instantiate_async`] to 86 /// create a [`W`]. 87 /// 88 /// * If you've instantiated the instance yourself already 89 /// then you can use [`W::new`]. 90 /// 91 /// These methods are all equivalent to one another and move 92 /// around the tradeoff of what work is performed when. 93 /// 94 /// [`Store`]: wasmtime::Store 95 /// [`Component`]: wasmtime::component::Component 96 /// [`Linker`]: wasmtime::component::Linker 97 pub struct W { 98 interface0: exports::foo::foo::simple_export::Guest, 99 interface1: exports::foo::foo::export_using_import::Guest, 100 interface2: exports::foo::foo::export_using_export1::Guest, 101 interface3: exports::foo::foo::export_using_export2::Guest, 102 } 103 const _: () = { 104 #[allow(unused_imports)] 105 use wasmtime::component::__internal::anyhow; 106 impl WIndices { 107 /// Creates a new copy of `WIndices` bindings which can then 108 /// be used to instantiate into a particular store. 109 /// 110 /// This method may fail if the component does not have the 111 /// required exports. 112 pub fn new<_T>( 113 _instance_pre: &wasmtime::component::InstancePre<_T>, 114 ) -> wasmtime::Result<Self> { 115 let _component = _instance_pre.component(); 116 let _instance_type = _instance_pre.instance_type(); 117 let interface0 = exports::foo::foo::simple_export::GuestIndices::new( 118 _instance_pre, 119 )?; 120 let interface1 = exports::foo::foo::export_using_import::GuestIndices::new( 121 _instance_pre, 122 )?; 123 let interface2 = exports::foo::foo::export_using_export1::GuestIndices::new( 124 _instance_pre, 125 )?; 126 let interface3 = exports::foo::foo::export_using_export2::GuestIndices::new( 127 _instance_pre, 128 )?; 129 Ok(WIndices { 130 interface0, 131 interface1, 132 interface2, 133 interface3, 134 }) 135 } 136 /// Uses the indices stored in `self` to load an instance 137 /// of [`W`] from the instance provided. 138 /// 139 /// Note that at this time this method will additionally 140 /// perform type-checks of all exports. 141 pub fn load( 142 &self, 143 mut store: impl wasmtime::AsContextMut, 144 instance: &wasmtime::component::Instance, 145 ) -> wasmtime::Result<W> { 146 let _ = &mut store; 147 let _instance = instance; 148 let interface0 = self.interface0.load(&mut store, &_instance)?; 149 let interface1 = self.interface1.load(&mut store, &_instance)?; 150 let interface2 = self.interface2.load(&mut store, &_instance)?; 151 let interface3 = self.interface3.load(&mut store, &_instance)?; 152 Ok(W { 153 interface0, 154 interface1, 155 interface2, 156 interface3, 157 }) 158 } 159 } 160 impl W { 161 /// Convenience wrapper around [`WPre::new`] and 162 /// [`WPre::instantiate_async`]. 163 pub async fn instantiate_async<_T>( 164 store: impl wasmtime::AsContextMut<Data = _T>, 165 component: &wasmtime::component::Component, 166 linker: &wasmtime::component::Linker<_T>, 167 ) -> wasmtime::Result<W> 168 where 169 _T: Send + 'static, 170 { 171 let pre = linker.instantiate_pre(component)?; 172 WPre::new(pre)?.instantiate_async(store).await 173 } 174 /// Convenience wrapper around [`WIndices::new`] and 175 /// [`WIndices::load`]. 176 pub fn new( 177 mut store: impl wasmtime::AsContextMut, 178 instance: &wasmtime::component::Instance, 179 ) -> wasmtime::Result<W> { 180 let indices = WIndices::new(&instance.instance_pre(&store))?; 181 indices.load(&mut store, instance) 182 } 183 pub fn add_to_linker<T, U>( 184 linker: &mut wasmtime::component::Linker<T>, 185 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 186 ) -> wasmtime::Result<()> 187 where 188 T: Send + foo::foo::transitive_import::Host + 'static, 189 U: Send + foo::foo::transitive_import::Host, 190 { 191 foo::foo::transitive_import::add_to_linker(linker, get)?; 192 Ok(()) 193 } 194 pub fn foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest { 195 &self.interface0 196 } 197 pub fn foo_foo_export_using_import( 198 &self, 199 ) -> &exports::foo::foo::export_using_import::Guest { 200 &self.interface1 201 } 202 pub fn foo_foo_export_using_export1( 203 &self, 204 ) -> &exports::foo::foo::export_using_export1::Guest { 205 &self.interface2 206 } 207 pub fn foo_foo_export_using_export2( 208 &self, 209 ) -> &exports::foo::foo::export_using_export2::Guest { 210 &self.interface3 211 } 212 } 213 }; 214 pub mod foo { 215 pub mod foo { 216 #[allow(clippy::all)] 217 pub mod transitive_import { 218 #[allow(unused_imports)] 219 use wasmtime::component::__internal::{anyhow, Box}; 220 pub enum Y {} 221 pub trait HostY: Sized { 222 fn drop( 223 &mut self, 224 rep: wasmtime::component::Resource<Y>, 225 ) -> wasmtime::Result<()>; 226 } 227 impl<_T: HostY + ?Sized> HostY for &mut _T { 228 fn drop( 229 &mut self, 230 rep: wasmtime::component::Resource<Y>, 231 ) -> wasmtime::Result<()> { 232 HostY::drop(*self, rep) 233 } 234 } 235 pub trait Host: HostY + Sized {} 236 pub trait GetHost< 237 T, 238 D, 239 >: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static { 240 type Host: Host + Send; 241 } 242 impl<F, T, D, O> GetHost<T, D> for F 243 where 244 F: Fn(T) -> O + Send + Sync + Copy + 'static, 245 O: Host + Send, 246 { 247 type Host = O; 248 } 249 pub fn add_to_linker_get_host< 250 T, 251 G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>, 252 >( 253 linker: &mut wasmtime::component::Linker<T>, 254 host_getter: G, 255 ) -> wasmtime::Result<()> 256 where 257 T: Send + 'static, 258 { 259 let mut inst = linker.instance("foo:foo/transitive-import")?; 260 inst.resource( 261 "y", 262 wasmtime::component::ResourceType::host::<Y>(), 263 move |mut store, rep| -> wasmtime::Result<()> { 264 HostY::drop( 265 &mut host_getter(store.data_mut()), 266 wasmtime::component::Resource::new_own(rep), 267 ) 268 }, 269 )?; 270 Ok(()) 271 } 272 pub fn add_to_linker<T, U>( 273 linker: &mut wasmtime::component::Linker<T>, 274 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 275 ) -> wasmtime::Result<()> 276 where 277 U: Host + Send, 278 T: Send + 'static, 279 { 280 add_to_linker_get_host(linker, get) 281 } 282 impl<_T: Host + ?Sized> Host for &mut _T {} 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<S: wasmtime::AsContextMut>( 389 &self, 390 mut store: S, 391 ) -> wasmtime::Result< 392 wasmtime::component::Promise<wasmtime::component::ResourceAny>, 393 > 394 where 395 <S as wasmtime::AsContext>::Data: Send + 'static, 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 promise = callee 404 .call_concurrent(store.as_context_mut(), ()) 405 .await?; 406 Ok(promise.map(|(v,)| v)) 407 } 408 pub async fn call_static_a<S: wasmtime::AsContextMut>( 409 &self, 410 mut store: S, 411 ) -> wasmtime::Result<wasmtime::component::Promise<u32>> 412 where 413 <S as wasmtime::AsContext>::Data: Send + 'static, 414 { 415 let callee = unsafe { 416 wasmtime::component::TypedFunc::< 417 (), 418 (u32,), 419 >::new_unchecked(self.funcs.static_a_static_a) 420 }; 421 let promise = callee 422 .call_concurrent(store.as_context_mut(), ()) 423 .await?; 424 Ok(promise.map(|(v,)| v)) 425 } 426 pub async fn call_method_a<S: wasmtime::AsContextMut>( 427 &self, 428 mut store: S, 429 arg0: wasmtime::component::ResourceAny, 430 ) -> wasmtime::Result<wasmtime::component::Promise<u32>> 431 where 432 <S as wasmtime::AsContext>::Data: Send + 'static, 433 { 434 let callee = unsafe { 435 wasmtime::component::TypedFunc::< 436 (wasmtime::component::ResourceAny,), 437 (u32,), 438 >::new_unchecked(self.funcs.method_a_method_a) 439 }; 440 let promise = callee 441 .call_concurrent(store.as_context_mut(), (arg0,)) 442 .await?; 443 Ok(promise.map(|(v,)| v)) 444 } 445 } 446 } 447 #[allow(clippy::all)] 448 pub mod export_using_import { 449 #[allow(unused_imports)] 450 use wasmtime::component::__internal::{anyhow, Box}; 451 pub type Y = super::super::super::super::foo::foo::transitive_import::Y; 452 pub type A = wasmtime::component::ResourceAny; 453 pub struct GuestA<'a> { 454 funcs: &'a Guest, 455 } 456 pub struct Guest { 457 constructor_a_constructor: wasmtime::component::Func, 458 static_a_static_a: wasmtime::component::Func, 459 method_a_method_a: wasmtime::component::Func, 460 } 461 #[derive(Clone)] 462 pub struct GuestIndices { 463 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 464 static_a_static_a: wasmtime::component::ComponentExportIndex, 465 method_a_method_a: wasmtime::component::ComponentExportIndex, 466 } 467 impl GuestIndices { 468 /// Constructor for [`GuestIndices`] which takes a 469 /// [`Component`](wasmtime::component::Component) as input and can be executed 470 /// before instantiation. 471 /// 472 /// This constructor can be used to front-load string lookups to find exports 473 /// within a component. 474 pub fn new<_T>( 475 _instance_pre: &wasmtime::component::InstancePre<_T>, 476 ) -> wasmtime::Result<GuestIndices> { 477 let instance = _instance_pre 478 .component() 479 .get_export_index(None, "foo:foo/export-using-import") 480 .ok_or_else(|| { 481 anyhow::anyhow!( 482 "no exported instance named `foo:foo/export-using-import`" 483 ) 484 })?; 485 let mut lookup = move |name| { 486 _instance_pre 487 .component() 488 .get_export_index(Some(&instance), name) 489 .ok_or_else(|| { 490 anyhow::anyhow!( 491 "instance export `foo:foo/export-using-import` does \ 492 not have export `{name}`" 493 ) 494 }) 495 }; 496 let _ = &mut lookup; 497 let constructor_a_constructor = lookup("[constructor]a")?; 498 let static_a_static_a = lookup("[static]a.static-a")?; 499 let method_a_method_a = lookup("[method]a.method-a")?; 500 Ok(GuestIndices { 501 constructor_a_constructor, 502 static_a_static_a, 503 method_a_method_a, 504 }) 505 } 506 pub fn load( 507 &self, 508 mut store: impl wasmtime::AsContextMut, 509 instance: &wasmtime::component::Instance, 510 ) -> wasmtime::Result<Guest> { 511 let _instance = instance; 512 let _instance_pre = _instance.instance_pre(&store); 513 let _instance_type = _instance_pre.instance_type(); 514 let mut store = store.as_context_mut(); 515 let _ = &mut store; 516 let constructor_a_constructor = *_instance 517 .get_typed_func::< 518 (wasmtime::component::Resource<Y>,), 519 (wasmtime::component::ResourceAny,), 520 >(&mut store, &self.constructor_a_constructor)? 521 .func(); 522 let static_a_static_a = *_instance 523 .get_typed_func::< 524 (), 525 (wasmtime::component::Resource<Y>,), 526 >(&mut store, &self.static_a_static_a)? 527 .func(); 528 let method_a_method_a = *_instance 529 .get_typed_func::< 530 ( 531 wasmtime::component::ResourceAny, 532 wasmtime::component::Resource<Y>, 533 ), 534 (wasmtime::component::Resource<Y>,), 535 >(&mut store, &self.method_a_method_a)? 536 .func(); 537 Ok(Guest { 538 constructor_a_constructor, 539 static_a_static_a, 540 method_a_method_a, 541 }) 542 } 543 } 544 impl Guest { 545 pub fn a(&self) -> GuestA<'_> { 546 GuestA { funcs: self } 547 } 548 } 549 impl GuestA<'_> { 550 pub async fn call_constructor<S: wasmtime::AsContextMut>( 551 &self, 552 mut store: S, 553 arg0: wasmtime::component::Resource<Y>, 554 ) -> wasmtime::Result< 555 wasmtime::component::Promise<wasmtime::component::ResourceAny>, 556 > 557 where 558 <S as wasmtime::AsContext>::Data: Send + 'static, 559 { 560 let callee = unsafe { 561 wasmtime::component::TypedFunc::< 562 (wasmtime::component::Resource<Y>,), 563 (wasmtime::component::ResourceAny,), 564 >::new_unchecked(self.funcs.constructor_a_constructor) 565 }; 566 let promise = callee 567 .call_concurrent(store.as_context_mut(), (arg0,)) 568 .await?; 569 Ok(promise.map(|(v,)| v)) 570 } 571 pub async fn call_static_a<S: wasmtime::AsContextMut>( 572 &self, 573 mut store: S, 574 ) -> wasmtime::Result< 575 wasmtime::component::Promise<wasmtime::component::Resource<Y>>, 576 > 577 where 578 <S as wasmtime::AsContext>::Data: Send + 'static, 579 { 580 let callee = unsafe { 581 wasmtime::component::TypedFunc::< 582 (), 583 (wasmtime::component::Resource<Y>,), 584 >::new_unchecked(self.funcs.static_a_static_a) 585 }; 586 let promise = callee 587 .call_concurrent(store.as_context_mut(), ()) 588 .await?; 589 Ok(promise.map(|(v,)| v)) 590 } 591 pub async fn call_method_a<S: wasmtime::AsContextMut>( 592 &self, 593 mut store: S, 594 arg0: wasmtime::component::ResourceAny, 595 arg1: wasmtime::component::Resource<Y>, 596 ) -> wasmtime::Result< 597 wasmtime::component::Promise<wasmtime::component::Resource<Y>>, 598 > 599 where 600 <S as wasmtime::AsContext>::Data: Send + 'static, 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 promise = callee 612 .call_concurrent(store.as_context_mut(), (arg0, arg1)) 613 .await?; 614 Ok(promise.map(|(v,)| v)) 615 } 616 } 617 } 618 #[allow(clippy::all)] 619 pub mod export_using_export1 { 620 #[allow(unused_imports)] 621 use wasmtime::component::__internal::{anyhow, Box}; 622 pub type A = wasmtime::component::ResourceAny; 623 pub struct GuestA<'a> { 624 funcs: &'a Guest, 625 } 626 pub struct Guest { 627 constructor_a_constructor: wasmtime::component::Func, 628 } 629 #[derive(Clone)] 630 pub struct GuestIndices { 631 constructor_a_constructor: wasmtime::component::ComponentExportIndex, 632 } 633 impl GuestIndices { 634 /// Constructor for [`GuestIndices`] which takes a 635 /// [`Component`](wasmtime::component::Component) as input and can be executed 636 /// before instantiation. 637 /// 638 /// This constructor can be used to front-load string lookups to find exports 639 /// within a component. 640 pub fn new<_T>( 641 _instance_pre: &wasmtime::component::InstancePre<_T>, 642 ) -> wasmtime::Result<GuestIndices> { 643 let instance = _instance_pre 644 .component() 645 .get_export_index(None, "foo:foo/export-using-export1") 646 .ok_or_else(|| { 647 anyhow::anyhow!( 648 "no exported instance named `foo:foo/export-using-export1`" 649 ) 650 })?; 651 let mut lookup = move |name| { 652 _instance_pre 653 .component() 654 .get_export_index(Some(&instance), name) 655 .ok_or_else(|| { 656 anyhow::anyhow!( 657 "instance export `foo:foo/export-using-export1` does \ 658 not have export `{name}`" 659 ) 660 }) 661 }; 662 let _ = &mut lookup; 663 let constructor_a_constructor = lookup("[constructor]a")?; 664 Ok(GuestIndices { 665 constructor_a_constructor, 666 }) 667 } 668 pub fn load( 669 &self, 670 mut store: impl wasmtime::AsContextMut, 671 instance: &wasmtime::component::Instance, 672 ) -> wasmtime::Result<Guest> { 673 let _instance = instance; 674 let _instance_pre = _instance.instance_pre(&store); 675 let _instance_type = _instance_pre.instance_type(); 676 let mut store = store.as_context_mut(); 677 let _ = &mut store; 678 let constructor_a_constructor = *_instance 679 .get_typed_func::< 680 (), 681 (wasmtime::component::ResourceAny,), 682 >(&mut store, &self.constructor_a_constructor)? 683 .func(); 684 Ok(Guest { constructor_a_constructor }) 685 } 686 } 687 impl Guest { 688 pub fn a(&self) -> GuestA<'_> { 689 GuestA { funcs: self } 690 } 691 } 692 impl GuestA<'_> { 693 pub async fn call_constructor<S: wasmtime::AsContextMut>( 694 &self, 695 mut store: S, 696 ) -> wasmtime::Result< 697 wasmtime::component::Promise<wasmtime::component::ResourceAny>, 698 > 699 where 700 <S as wasmtime::AsContext>::Data: Send + 'static, 701 { 702 let callee = unsafe { 703 wasmtime::component::TypedFunc::< 704 (), 705 (wasmtime::component::ResourceAny,), 706 >::new_unchecked(self.funcs.constructor_a_constructor) 707 }; 708 let promise = callee 709 .call_concurrent(store.as_context_mut(), ()) 710 .await?; 711 Ok(promise.map(|(v,)| v)) 712 } 713 } 714 } 715 #[allow(clippy::all)] 716 pub mod export_using_export2 { 717 #[allow(unused_imports)] 718 use wasmtime::component::__internal::{anyhow, Box}; 719 pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A; 720 pub type B = wasmtime::component::ResourceAny; 721 pub struct GuestB<'a> { 722 funcs: &'a Guest, 723 } 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 anyhow::anyhow!( 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 anyhow::anyhow!( 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< 796 wasmtime::component::Promise<wasmtime::component::ResourceAny>, 797 > 798 where 799 <S as wasmtime::AsContext>::Data: Send + 'static, 800 { 801 let callee = unsafe { 802 wasmtime::component::TypedFunc::< 803 (wasmtime::component::ResourceAny,), 804 (wasmtime::component::ResourceAny,), 805 >::new_unchecked(self.funcs.constructor_b_constructor) 806 }; 807 let promise = callee 808 .call_concurrent(store.as_context_mut(), (arg0,)) 809 .await?; 810 Ok(promise.map(|(v,)| v)) 811 } 812 } 813 } 814 } 815 } 816 } 817