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