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