1 pub enum WorldResource {} 2 pub trait HostWorldResourceWithStore: wasmtime::component::HasData + Send {} 3 impl<_T: ?Sized> HostWorldResourceWithStore for _T 4 where 5 _T: wasmtime::component::HasData + Send, 6 {} 7 pub trait HostWorldResource: Send { new( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<WorldResource>, > + Send8 fn new( 9 &mut self, 10 ) -> impl ::core::future::Future< 11 Output = wasmtime::component::Resource<WorldResource>, 12 > + Send; foo( &mut self, self_: wasmtime::component::Resource<WorldResource>, ) -> impl ::core::future::Future<Output = ()> + Send13 fn foo( 14 &mut self, 15 self_: wasmtime::component::Resource<WorldResource>, 16 ) -> impl ::core::future::Future<Output = ()> + Send; static_foo(&mut self) -> impl ::core::future::Future<Output = ()> + Send17 fn static_foo(&mut self) -> impl ::core::future::Future<Output = ()> + Send; drop( &mut self, rep: wasmtime::component::Resource<WorldResource>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send18 fn drop( 19 &mut self, 20 rep: wasmtime::component::Resource<WorldResource>, 21 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 22 } 23 impl<_T: HostWorldResource + ?Sized + Send> HostWorldResource for &mut _T { new( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<WorldResource>, > + Send24 fn new( 25 &mut self, 26 ) -> impl ::core::future::Future< 27 Output = wasmtime::component::Resource<WorldResource>, 28 > + Send { 29 async move { HostWorldResource::new(*self).await } 30 } foo( &mut self, self_: wasmtime::component::Resource<WorldResource>, ) -> impl ::core::future::Future<Output = ()> + Send31 fn foo( 32 &mut self, 33 self_: wasmtime::component::Resource<WorldResource>, 34 ) -> impl ::core::future::Future<Output = ()> + Send { 35 async move { HostWorldResource::foo(*self, self_).await } 36 } static_foo(&mut self) -> impl ::core::future::Future<Output = ()> + Send37 fn static_foo(&mut self) -> impl ::core::future::Future<Output = ()> + Send { 38 async move { HostWorldResource::static_foo(*self).await } 39 } drop( &mut self, rep: wasmtime::component::Resource<WorldResource>, ) -> wasmtime::Result<()>40 async fn drop( 41 &mut self, 42 rep: wasmtime::component::Resource<WorldResource>, 43 ) -> wasmtime::Result<()> { 44 HostWorldResource::drop(*self, rep).await 45 } 46 } 47 /// Auto-generated bindings for a pre-instantiated version of a 48 /// component which implements the world `the-world`. 49 /// 50 /// This structure is created through [`TheWorldPre::new`] which 51 /// takes a [`InstancePre`](wasmtime::component::InstancePre) that 52 /// has been created through a [`Linker`](wasmtime::component::Linker). 53 /// 54 /// For more information see [`TheWorld`] as well. 55 pub struct TheWorldPre<T: 'static> { 56 instance_pre: wasmtime::component::InstancePre<T>, 57 indices: TheWorldIndices, 58 } 59 impl<T: 'static> Clone for TheWorldPre<T> { clone(&self) -> Self60 fn clone(&self) -> Self { 61 Self { 62 instance_pre: self.instance_pre.clone(), 63 indices: self.indices.clone(), 64 } 65 } 66 } 67 impl<_T: 'static> TheWorldPre<_T> { 68 /// Creates a new copy of `TheWorldPre` bindings which can then 69 /// be used to instantiate into a particular store. 70 /// 71 /// This method may fail if the component behind `instance_pre` 72 /// does not have the required exports. new( instance_pre: wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>73 pub fn new( 74 instance_pre: wasmtime::component::InstancePre<_T>, 75 ) -> wasmtime::Result<Self> { 76 let indices = TheWorldIndices::new(&instance_pre)?; 77 Ok(Self { instance_pre, indices }) 78 } engine(&self) -> &wasmtime::Engine79 pub fn engine(&self) -> &wasmtime::Engine { 80 self.instance_pre.engine() 81 } instance_pre(&self) -> &wasmtime::component::InstancePre<_T>82 pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> { 83 &self.instance_pre 84 } 85 /// Instantiates a new instance of [`TheWorld`] within the 86 /// `store` provided. 87 /// 88 /// This function will use `self` as the pre-instantiated 89 /// instance to perform instantiation. Afterwards the preloaded 90 /// indices in `self` are used to lookup all exports on the 91 /// resulting instance. instantiate( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<TheWorld>92 pub fn instantiate( 93 &self, 94 mut store: impl wasmtime::AsContextMut<Data = _T>, 95 ) -> wasmtime::Result<TheWorld> { 96 let mut store = store.as_context_mut(); 97 let instance = self.instance_pre.instantiate(&mut store)?; 98 self.indices.load(&mut store, &instance) 99 } 100 } 101 impl<_T: Send + 'static> TheWorldPre<_T> { 102 /// Same as [`Self::instantiate`], except with `async`. instantiate_async( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<TheWorld>103 pub async fn instantiate_async( 104 &self, 105 mut store: impl wasmtime::AsContextMut<Data = _T>, 106 ) -> wasmtime::Result<TheWorld> { 107 let mut store = store.as_context_mut(); 108 let instance = self.instance_pre.instantiate_async(&mut store).await?; 109 self.indices.load(&mut store, &instance) 110 } 111 } 112 /// Auto-generated bindings for index of the exports of 113 /// `the-world`. 114 /// 115 /// This is an implementation detail of [`TheWorldPre`] and can 116 /// be constructed if needed as well. 117 /// 118 /// For more information see [`TheWorld`] as well. 119 #[derive(Clone)] 120 pub struct TheWorldIndices { 121 interface1: exports::foo::foo::uses_resource_transitively::GuestIndices, 122 some_world_func2: wasmtime::component::ComponentExportIndex, 123 } 124 /// Auto-generated bindings for an instance a component which 125 /// implements the world `the-world`. 126 /// 127 /// This structure can be created through a number of means 128 /// depending on your requirements and what you have on hand: 129 /// 130 /// * The most convenient way is to use 131 /// [`TheWorld::instantiate`] which only needs a 132 /// [`Store`], [`Component`], and [`Linker`]. 133 /// 134 /// * Alternatively you can create a [`TheWorldPre`] ahead of 135 /// time with a [`Component`] to front-load string lookups 136 /// of exports once instead of per-instantiation. This 137 /// method then uses [`TheWorldPre::instantiate`] to 138 /// create a [`TheWorld`]. 139 /// 140 /// * If you've instantiated the instance yourself already 141 /// then you can use [`TheWorld::new`]. 142 /// 143 /// These methods are all equivalent to one another and move 144 /// around the tradeoff of what work is performed when. 145 /// 146 /// [`Store`]: wasmtime::Store 147 /// [`Component`]: wasmtime::component::Component 148 /// [`Linker`]: wasmtime::component::Linker 149 pub struct TheWorld { 150 interface1: exports::foo::foo::uses_resource_transitively::Guest, 151 some_world_func2: wasmtime::component::Func, 152 } 153 pub trait TheWorldImportsWithStore: wasmtime::component::HasData + HostWorldResourceWithStore + Send {} 154 impl<_T: ?Sized> TheWorldImportsWithStore for _T 155 where 156 _T: wasmtime::component::HasData + HostWorldResourceWithStore + Send, 157 {} 158 pub trait TheWorldImports: HostWorldResource + Send { some_world_func( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<WorldResource>, > + Send159 fn some_world_func( 160 &mut self, 161 ) -> impl ::core::future::Future< 162 Output = wasmtime::component::Resource<WorldResource>, 163 > + Send; 164 } 165 impl<_T: TheWorldImports + ?Sized + Send> TheWorldImports for &mut _T { some_world_func( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<WorldResource>, > + Send166 fn some_world_func( 167 &mut self, 168 ) -> impl ::core::future::Future< 169 Output = wasmtime::component::Resource<WorldResource>, 170 > + Send { 171 async move { TheWorldImports::some_world_func(*self).await } 172 } 173 } 174 const _: () = { 175 impl TheWorldIndices { 176 /// Creates a new copy of `TheWorldIndices` bindings which can then 177 /// be used to instantiate into a particular store. 178 /// 179 /// This method may fail if the component does not have the 180 /// required exports. new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>181 pub fn new<_T>( 182 _instance_pre: &wasmtime::component::InstancePre<_T>, 183 ) -> wasmtime::Result<Self> { 184 let _component = _instance_pre.component(); 185 let _instance_type = _instance_pre.instance_type(); 186 let interface1 = exports::foo::foo::uses_resource_transitively::GuestIndices::new( 187 _instance_pre, 188 )?; 189 let some_world_func2 = { 190 let (item, index) = _component 191 .get_export(None, "some-world-func2") 192 .ok_or_else(|| { 193 wasmtime::format_err!("no export `some-world-func2` found") 194 })?; 195 match item { 196 wasmtime::component::types::ComponentItem::ComponentFunc(func) => { 197 wasmtime::error::Context::context( 198 func 199 .typecheck::< 200 (), 201 (wasmtime::component::Resource<WorldResource>,), 202 >(&_instance_type), 203 "type-checking export func `some-world-func2`", 204 )?; 205 index 206 } 207 _ => { 208 Err( 209 wasmtime::format_err!( 210 "export `some-world-func2` is not a function" 211 ), 212 )? 213 } 214 } 215 }; 216 Ok(TheWorldIndices { 217 interface1, 218 some_world_func2, 219 }) 220 } 221 /// Uses the indices stored in `self` to load an instance 222 /// of [`TheWorld`] from the instance provided. 223 /// 224 /// Note that at this time this method will additionally 225 /// perform type-checks of all exports. load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<TheWorld>226 pub fn load( 227 &self, 228 mut store: impl wasmtime::AsContextMut, 229 instance: &wasmtime::component::Instance, 230 ) -> wasmtime::Result<TheWorld> { 231 let _ = &mut store; 232 let _instance = instance; 233 let interface1 = self.interface1.load(&mut store, &_instance)?; 234 let some_world_func2 = *_instance 235 .get_typed_func::< 236 (), 237 (wasmtime::component::Resource<WorldResource>,), 238 >(&mut store, &self.some_world_func2)? 239 .func(); 240 Ok(TheWorld { 241 interface1, 242 some_world_func2, 243 }) 244 } 245 } 246 impl TheWorld { 247 /// Convenience wrapper around [`TheWorldPre::new`] and 248 /// [`TheWorldPre::instantiate`]. instantiate<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<TheWorld>249 pub fn instantiate<_T>( 250 store: impl wasmtime::AsContextMut<Data = _T>, 251 component: &wasmtime::component::Component, 252 linker: &wasmtime::component::Linker<_T>, 253 ) -> wasmtime::Result<TheWorld> { 254 let pre = linker.instantiate_pre(component)?; 255 TheWorldPre::new(pre)?.instantiate(store) 256 } 257 /// Convenience wrapper around [`TheWorldIndices::new`] and 258 /// [`TheWorldIndices::load`]. new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<TheWorld>259 pub fn new( 260 mut store: impl wasmtime::AsContextMut, 261 instance: &wasmtime::component::Instance, 262 ) -> wasmtime::Result<TheWorld> { 263 let indices = TheWorldIndices::new(&instance.instance_pre(&store))?; 264 indices.load(&mut store, instance) 265 } 266 /// Convenience wrapper around [`TheWorldPre::new`] and 267 /// [`TheWorldPre::instantiate_async`]. instantiate_async<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<TheWorld> where _T: Send,268 pub async fn instantiate_async<_T>( 269 store: impl wasmtime::AsContextMut<Data = _T>, 270 component: &wasmtime::component::Component, 271 linker: &wasmtime::component::Linker<_T>, 272 ) -> wasmtime::Result<TheWorld> 273 where 274 _T: Send, 275 { 276 let pre = linker.instantiate_pre(component)?; 277 TheWorldPre::new(pre)?.instantiate_async(store).await 278 } add_to_linker_imports<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, T: 'static + Send,279 pub fn add_to_linker_imports<T, D>( 280 linker: &mut wasmtime::component::Linker<T>, 281 host_getter: fn(&mut T) -> D::Data<'_>, 282 ) -> wasmtime::Result<()> 283 where 284 D: TheWorldImportsWithStore, 285 for<'a> D::Data<'a>: TheWorldImports, 286 T: 'static + Send, 287 { 288 let mut linker = linker.root(); 289 linker 290 .resource_async( 291 "world-resource", 292 wasmtime::component::ResourceType::host::<WorldResource>(), 293 move |mut store, rep| { 294 wasmtime::component::__internal::Box::new(async move { 295 wasmtime::ToWasmtimeResult::to_wasmtime_result( 296 HostWorldResource::drop( 297 &mut host_getter(store.data_mut()), 298 wasmtime::component::Resource::new_own(rep), 299 ) 300 .await, 301 ) 302 }) 303 }, 304 )?; 305 linker 306 .func_wrap_async( 307 "some-world-func", 308 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 309 wasmtime::component::__internal::Box::new(async move { 310 let host = &mut host_getter(caller.data_mut()); 311 let r = TheWorldImports::some_world_func(host).await; 312 Ok((r,)) 313 }) 314 }, 315 )?; 316 linker 317 .func_wrap_async( 318 "[constructor]world-resource", 319 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 320 wasmtime::component::__internal::Box::new(async move { 321 let host = &mut host_getter(caller.data_mut()); 322 let r = HostWorldResource::new(host).await; 323 Ok((r,)) 324 }) 325 }, 326 )?; 327 linker 328 .func_wrap_async( 329 "[method]world-resource.foo", 330 move | 331 mut caller: wasmtime::StoreContextMut<'_, T>, 332 (arg0,): (wasmtime::component::Resource<WorldResource>,)| 333 { 334 wasmtime::component::__internal::Box::new(async move { 335 let host = &mut host_getter(caller.data_mut()); 336 let r = HostWorldResource::foo(host, arg0).await; 337 Ok(r) 338 }) 339 }, 340 )?; 341 linker 342 .func_wrap_async( 343 "[static]world-resource.static-foo", 344 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 345 wasmtime::component::__internal::Box::new(async move { 346 let host = &mut host_getter(caller.data_mut()); 347 let r = HostWorldResource::static_foo(host).await; 348 Ok(r) 349 }) 350 }, 351 )?; 352 Ok(()) 353 } add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: foo::foo::resources::HostWithStore + foo::foo::long_use_chain1::HostWithStore + foo::foo::long_use_chain2::HostWithStore + foo::foo::long_use_chain3::HostWithStore + foo::foo::long_use_chain4::HostWithStore + foo::foo::transitive_interface_with_resource::HostWithStore + TheWorldImportsWithStore + Send, for<'a> D::Data< 'a, >: foo::foo::resources::Host + foo::foo::long_use_chain1::Host + foo::foo::long_use_chain2::Host + foo::foo::long_use_chain3::Host + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports + Send, T: 'static + Send,354 pub fn add_to_linker<T, D>( 355 linker: &mut wasmtime::component::Linker<T>, 356 host_getter: fn(&mut T) -> D::Data<'_>, 357 ) -> wasmtime::Result<()> 358 where 359 D: foo::foo::resources::HostWithStore 360 + foo::foo::long_use_chain1::HostWithStore 361 + foo::foo::long_use_chain2::HostWithStore 362 + foo::foo::long_use_chain3::HostWithStore 363 + foo::foo::long_use_chain4::HostWithStore 364 + foo::foo::transitive_interface_with_resource::HostWithStore 365 + TheWorldImportsWithStore + Send, 366 for<'a> D::Data< 367 'a, 368 >: foo::foo::resources::Host + foo::foo::long_use_chain1::Host 369 + foo::foo::long_use_chain2::Host + foo::foo::long_use_chain3::Host 370 + foo::foo::long_use_chain4::Host 371 + foo::foo::transitive_interface_with_resource::Host + TheWorldImports 372 + Send, 373 T: 'static + Send, 374 { 375 Self::add_to_linker_imports::<T, D>(linker, host_getter)?; 376 foo::foo::resources::add_to_linker::<T, D>(linker, host_getter)?; 377 foo::foo::long_use_chain1::add_to_linker::<T, D>(linker, host_getter)?; 378 foo::foo::long_use_chain2::add_to_linker::<T, D>(linker, host_getter)?; 379 foo::foo::long_use_chain3::add_to_linker::<T, D>(linker, host_getter)?; 380 foo::foo::long_use_chain4::add_to_linker::<T, D>(linker, host_getter)?; 381 foo::foo::transitive_interface_with_resource::add_to_linker::< 382 T, 383 D, 384 >(linker, host_getter)?; 385 Ok(()) 386 } call_some_world_func2<S: wasmtime::AsContextMut>( &self, mut store: S, ) -> wasmtime::Result<wasmtime::component::Resource<WorldResource>> where <S as wasmtime::AsContext>::Data: Send,387 pub async fn call_some_world_func2<S: wasmtime::AsContextMut>( 388 &self, 389 mut store: S, 390 ) -> wasmtime::Result<wasmtime::component::Resource<WorldResource>> 391 where 392 <S as wasmtime::AsContext>::Data: Send, 393 { 394 let callee = unsafe { 395 wasmtime::component::TypedFunc::< 396 (), 397 (wasmtime::component::Resource<WorldResource>,), 398 >::new_unchecked(self.some_world_func2) 399 }; 400 let (ret0,) = callee.call_async(store.as_context_mut(), ()).await?; 401 Ok(ret0) 402 } foo_foo_uses_resource_transitively( &self, ) -> &exports::foo::foo::uses_resource_transitively::Guest403 pub fn foo_foo_uses_resource_transitively( 404 &self, 405 ) -> &exports::foo::foo::uses_resource_transitively::Guest { 406 &self.interface1 407 } 408 } 409 }; 410 pub mod foo { 411 pub mod foo { 412 #[allow(clippy::all)] 413 pub mod resources { 414 #[allow(unused_imports)] 415 use wasmtime::component::__internal::Box; 416 pub enum Bar {} 417 pub trait HostBarWithStore: wasmtime::component::HasData + Send {} 418 impl<_T: ?Sized> HostBarWithStore for _T 419 where 420 _T: wasmtime::component::HasData + Send, 421 {} 422 pub trait HostBar: Send { new( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<Bar>, > + Send423 fn new( 424 &mut self, 425 ) -> impl ::core::future::Future< 426 Output = wasmtime::component::Resource<Bar>, 427 > + Send; static_a( &mut self, ) -> impl ::core::future::Future<Output = u32> + Send428 fn static_a( 429 &mut self, 430 ) -> impl ::core::future::Future<Output = u32> + Send; method_a( &mut self, self_: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = u32> + Send431 fn method_a( 432 &mut self, 433 self_: wasmtime::component::Resource<Bar>, 434 ) -> impl ::core::future::Future<Output = u32> + Send; drop( &mut self, rep: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send435 fn drop( 436 &mut self, 437 rep: wasmtime::component::Resource<Bar>, 438 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 439 } 440 impl<_T: HostBar + ?Sized + Send> HostBar for &mut _T { new( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<Bar>, > + Send441 fn new( 442 &mut self, 443 ) -> impl ::core::future::Future< 444 Output = wasmtime::component::Resource<Bar>, 445 > + Send { 446 async move { HostBar::new(*self).await } 447 } static_a( &mut self, ) -> impl ::core::future::Future<Output = u32> + Send448 fn static_a( 449 &mut self, 450 ) -> impl ::core::future::Future<Output = u32> + Send { 451 async move { HostBar::static_a(*self).await } 452 } method_a( &mut self, self_: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = u32> + Send453 fn method_a( 454 &mut self, 455 self_: wasmtime::component::Resource<Bar>, 456 ) -> impl ::core::future::Future<Output = u32> + Send { 457 async move { HostBar::method_a(*self, self_).await } 458 } drop( &mut self, rep: wasmtime::component::Resource<Bar>, ) -> wasmtime::Result<()>459 async fn drop( 460 &mut self, 461 rep: wasmtime::component::Resource<Bar>, 462 ) -> wasmtime::Result<()> { 463 HostBar::drop(*self, rep).await 464 } 465 } 466 #[derive(wasmtime::component::ComponentType)] 467 #[derive(wasmtime::component::Lift)] 468 #[derive(wasmtime::component::Lower)] 469 #[component(record)] 470 pub struct NestedOwn { 471 #[component(name = "nested-bar")] 472 pub nested_bar: wasmtime::component::Resource<Bar>, 473 } 474 impl core::fmt::Debug for NestedOwn { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result475 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 476 f.debug_struct("NestedOwn") 477 .field("nested-bar", &self.nested_bar) 478 .finish() 479 } 480 } 481 const _: () = { 482 assert!( 483 4 == < NestedOwn as wasmtime::component::ComponentType >::SIZE32 484 ); 485 assert!( 486 4 == < NestedOwn as wasmtime::component::ComponentType >::ALIGN32 487 ); 488 }; 489 #[derive(wasmtime::component::ComponentType)] 490 #[derive(wasmtime::component::Lift)] 491 #[derive(wasmtime::component::Lower)] 492 #[component(record)] 493 pub struct NestedBorrow { 494 #[component(name = "nested-bar")] 495 pub nested_bar: wasmtime::component::Resource<Bar>, 496 } 497 impl core::fmt::Debug for NestedBorrow { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result498 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 499 f.debug_struct("NestedBorrow") 500 .field("nested-bar", &self.nested_bar) 501 .finish() 502 } 503 } 504 const _: () = { 505 assert!( 506 4 == < NestedBorrow as wasmtime::component::ComponentType >::SIZE32 507 ); 508 assert!( 509 4 == < NestedBorrow as wasmtime::component::ComponentType >::ALIGN32 510 ); 511 }; 512 pub type SomeHandle = wasmtime::component::Resource<Bar>; 513 const _: () = { 514 assert!( 515 4 == < SomeHandle as wasmtime::component::ComponentType >::SIZE32 516 ); 517 assert!( 518 4 == < SomeHandle as wasmtime::component::ComponentType >::ALIGN32 519 ); 520 }; 521 pub enum Fallible {} 522 pub trait HostFallibleWithStore: wasmtime::component::HasData + Send {} 523 impl<_T: ?Sized> HostFallibleWithStore for _T 524 where 525 _T: wasmtime::component::HasData + Send, 526 {} 527 pub trait HostFallible: Send { new( &mut self, ) -> impl ::core::future::Future< Output = Result< wasmtime::component::Resource<Fallible>, wasmtime::component::__internal::String, >, > + Send528 fn new( 529 &mut self, 530 ) -> impl ::core::future::Future< 531 Output = Result< 532 wasmtime::component::Resource<Fallible>, 533 wasmtime::component::__internal::String, 534 >, 535 > + Send; drop( &mut self, rep: wasmtime::component::Resource<Fallible>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send536 fn drop( 537 &mut self, 538 rep: wasmtime::component::Resource<Fallible>, 539 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 540 } 541 impl<_T: HostFallible + ?Sized + Send> HostFallible for &mut _T { new( &mut self, ) -> impl ::core::future::Future< Output = Result< wasmtime::component::Resource<Fallible>, wasmtime::component::__internal::String, >, > + Send542 fn new( 543 &mut self, 544 ) -> impl ::core::future::Future< 545 Output = Result< 546 wasmtime::component::Resource<Fallible>, 547 wasmtime::component::__internal::String, 548 >, 549 > + Send { 550 async move { HostFallible::new(*self).await } 551 } drop( &mut self, rep: wasmtime::component::Resource<Fallible>, ) -> wasmtime::Result<()>552 async fn drop( 553 &mut self, 554 rep: wasmtime::component::Resource<Fallible>, 555 ) -> wasmtime::Result<()> { 556 HostFallible::drop(*self, rep).await 557 } 558 } 559 pub trait HostWithStore: wasmtime::component::HasData + HostBarWithStore + HostFallibleWithStore + Send {} 560 impl<_T: ?Sized> HostWithStore for _T 561 where 562 _T: wasmtime::component::HasData + HostBarWithStore 563 + HostFallibleWithStore + Send, 564 {} 565 pub trait Host: HostBar + HostFallible + Send { bar_own_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = ()> + Send566 fn bar_own_arg( 567 &mut self, 568 x: wasmtime::component::Resource<Bar>, 569 ) -> impl ::core::future::Future<Output = ()> + Send; bar_borrow_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = ()> + Send570 fn bar_borrow_arg( 571 &mut self, 572 x: wasmtime::component::Resource<Bar>, 573 ) -> impl ::core::future::Future<Output = ()> + Send; bar_result( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<Bar>, > + Send574 fn bar_result( 575 &mut self, 576 ) -> impl ::core::future::Future< 577 Output = wasmtime::component::Resource<Bar>, 578 > + Send; tuple_own_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> impl ::core::future::Future<Output = ()> + Send579 fn tuple_own_arg( 580 &mut self, 581 x: (wasmtime::component::Resource<Bar>, u32), 582 ) -> impl ::core::future::Future<Output = ()> + Send; tuple_borrow_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> impl ::core::future::Future<Output = ()> + Send583 fn tuple_borrow_arg( 584 &mut self, 585 x: (wasmtime::component::Resource<Bar>, u32), 586 ) -> impl ::core::future::Future<Output = ()> + Send; tuple_result( &mut self, ) -> impl ::core::future::Future< Output = (wasmtime::component::Resource<Bar>, u32), > + Send587 fn tuple_result( 588 &mut self, 589 ) -> impl ::core::future::Future< 590 Output = (wasmtime::component::Resource<Bar>, u32), 591 > + Send; option_own_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> impl ::core::future::Future<Output = ()> + Send592 fn option_own_arg( 593 &mut self, 594 x: Option<wasmtime::component::Resource<Bar>>, 595 ) -> impl ::core::future::Future<Output = ()> + Send; option_borrow_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> impl ::core::future::Future<Output = ()> + Send596 fn option_borrow_arg( 597 &mut self, 598 x: Option<wasmtime::component::Resource<Bar>>, 599 ) -> impl ::core::future::Future<Output = ()> + Send; option_result( &mut self, ) -> impl ::core::future::Future< Output = Option<wasmtime::component::Resource<Bar>>, > + Send600 fn option_result( 601 &mut self, 602 ) -> impl ::core::future::Future< 603 Output = Option<wasmtime::component::Resource<Bar>>, 604 > + Send; result_own_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> impl ::core::future::Future<Output = ()> + Send605 fn result_own_arg( 606 &mut self, 607 x: Result<wasmtime::component::Resource<Bar>, ()>, 608 ) -> impl ::core::future::Future<Output = ()> + Send; result_borrow_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> impl ::core::future::Future<Output = ()> + Send609 fn result_borrow_arg( 610 &mut self, 611 x: Result<wasmtime::component::Resource<Bar>, ()>, 612 ) -> impl ::core::future::Future<Output = ()> + Send; result_result( &mut self, ) -> impl ::core::future::Future< Output = Result<wasmtime::component::Resource<Bar>, ()>, > + Send613 fn result_result( 614 &mut self, 615 ) -> impl ::core::future::Future< 616 Output = Result<wasmtime::component::Resource<Bar>, ()>, 617 > + Send; list_own_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> impl ::core::future::Future<Output = ()> + Send618 fn list_own_arg( 619 &mut self, 620 x: wasmtime::component::__internal::Vec< 621 wasmtime::component::Resource<Bar>, 622 >, 623 ) -> impl ::core::future::Future<Output = ()> + Send; list_borrow_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> impl ::core::future::Future<Output = ()> + Send624 fn list_borrow_arg( 625 &mut self, 626 x: wasmtime::component::__internal::Vec< 627 wasmtime::component::Resource<Bar>, 628 >, 629 ) -> impl ::core::future::Future<Output = ()> + Send; list_result( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, > + Send630 fn list_result( 631 &mut self, 632 ) -> impl ::core::future::Future< 633 Output = wasmtime::component::__internal::Vec< 634 wasmtime::component::Resource<Bar>, 635 >, 636 > + Send; record_own_arg( &mut self, x: NestedOwn, ) -> impl ::core::future::Future<Output = ()> + Send637 fn record_own_arg( 638 &mut self, 639 x: NestedOwn, 640 ) -> impl ::core::future::Future<Output = ()> + Send; record_borrow_arg( &mut self, x: NestedBorrow, ) -> impl ::core::future::Future<Output = ()> + Send641 fn record_borrow_arg( 642 &mut self, 643 x: NestedBorrow, 644 ) -> impl ::core::future::Future<Output = ()> + Send; record_result( &mut self, ) -> impl ::core::future::Future<Output = NestedOwn> + Send645 fn record_result( 646 &mut self, 647 ) -> impl ::core::future::Future<Output = NestedOwn> + Send; func_with_handle_typedef( &mut self, x: SomeHandle, ) -> impl ::core::future::Future<Output = ()> + Send648 fn func_with_handle_typedef( 649 &mut self, 650 x: SomeHandle, 651 ) -> impl ::core::future::Future<Output = ()> + Send; 652 } 653 impl<_T: Host + ?Sized + Send> Host for &mut _T { bar_own_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = ()> + Send654 fn bar_own_arg( 655 &mut self, 656 x: wasmtime::component::Resource<Bar>, 657 ) -> impl ::core::future::Future<Output = ()> + Send { 658 async move { Host::bar_own_arg(*self, x).await } 659 } bar_borrow_arg( &mut self, x: wasmtime::component::Resource<Bar>, ) -> impl ::core::future::Future<Output = ()> + Send660 fn bar_borrow_arg( 661 &mut self, 662 x: wasmtime::component::Resource<Bar>, 663 ) -> impl ::core::future::Future<Output = ()> + Send { 664 async move { Host::bar_borrow_arg(*self, x).await } 665 } bar_result( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<Bar>, > + Send666 fn bar_result( 667 &mut self, 668 ) -> impl ::core::future::Future< 669 Output = wasmtime::component::Resource<Bar>, 670 > + Send { 671 async move { Host::bar_result(*self).await } 672 } tuple_own_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> impl ::core::future::Future<Output = ()> + Send673 fn tuple_own_arg( 674 &mut self, 675 x: (wasmtime::component::Resource<Bar>, u32), 676 ) -> impl ::core::future::Future<Output = ()> + Send { 677 async move { Host::tuple_own_arg(*self, x).await } 678 } tuple_borrow_arg( &mut self, x: (wasmtime::component::Resource<Bar>, u32), ) -> impl ::core::future::Future<Output = ()> + Send679 fn tuple_borrow_arg( 680 &mut self, 681 x: (wasmtime::component::Resource<Bar>, u32), 682 ) -> impl ::core::future::Future<Output = ()> + Send { 683 async move { Host::tuple_borrow_arg(*self, x).await } 684 } tuple_result( &mut self, ) -> impl ::core::future::Future< Output = (wasmtime::component::Resource<Bar>, u32), > + Send685 fn tuple_result( 686 &mut self, 687 ) -> impl ::core::future::Future< 688 Output = (wasmtime::component::Resource<Bar>, u32), 689 > + Send { 690 async move { Host::tuple_result(*self).await } 691 } option_own_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> impl ::core::future::Future<Output = ()> + Send692 fn option_own_arg( 693 &mut self, 694 x: Option<wasmtime::component::Resource<Bar>>, 695 ) -> impl ::core::future::Future<Output = ()> + Send { 696 async move { Host::option_own_arg(*self, x).await } 697 } option_borrow_arg( &mut self, x: Option<wasmtime::component::Resource<Bar>>, ) -> impl ::core::future::Future<Output = ()> + Send698 fn option_borrow_arg( 699 &mut self, 700 x: Option<wasmtime::component::Resource<Bar>>, 701 ) -> impl ::core::future::Future<Output = ()> + Send { 702 async move { Host::option_borrow_arg(*self, x).await } 703 } option_result( &mut self, ) -> impl ::core::future::Future< Output = Option<wasmtime::component::Resource<Bar>>, > + Send704 fn option_result( 705 &mut self, 706 ) -> impl ::core::future::Future< 707 Output = Option<wasmtime::component::Resource<Bar>>, 708 > + Send { 709 async move { Host::option_result(*self).await } 710 } result_own_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> impl ::core::future::Future<Output = ()> + Send711 fn result_own_arg( 712 &mut self, 713 x: Result<wasmtime::component::Resource<Bar>, ()>, 714 ) -> impl ::core::future::Future<Output = ()> + Send { 715 async move { Host::result_own_arg(*self, x).await } 716 } result_borrow_arg( &mut self, x: Result<wasmtime::component::Resource<Bar>, ()>, ) -> impl ::core::future::Future<Output = ()> + Send717 fn result_borrow_arg( 718 &mut self, 719 x: Result<wasmtime::component::Resource<Bar>, ()>, 720 ) -> impl ::core::future::Future<Output = ()> + Send { 721 async move { Host::result_borrow_arg(*self, x).await } 722 } result_result( &mut self, ) -> impl ::core::future::Future< Output = Result<wasmtime::component::Resource<Bar>, ()>, > + Send723 fn result_result( 724 &mut self, 725 ) -> impl ::core::future::Future< 726 Output = Result<wasmtime::component::Resource<Bar>, ()>, 727 > + Send { 728 async move { Host::result_result(*self).await } 729 } list_own_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> impl ::core::future::Future<Output = ()> + Send730 fn list_own_arg( 731 &mut self, 732 x: wasmtime::component::__internal::Vec< 733 wasmtime::component::Resource<Bar>, 734 >, 735 ) -> impl ::core::future::Future<Output = ()> + Send { 736 async move { Host::list_own_arg(*self, x).await } 737 } list_borrow_arg( &mut self, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, ) -> impl ::core::future::Future<Output = ()> + Send738 fn list_borrow_arg( 739 &mut self, 740 x: wasmtime::component::__internal::Vec< 741 wasmtime::component::Resource<Bar>, 742 >, 743 ) -> impl ::core::future::Future<Output = ()> + Send { 744 async move { Host::list_borrow_arg(*self, x).await } 745 } list_result( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec< wasmtime::component::Resource<Bar>, >, > + Send746 fn list_result( 747 &mut self, 748 ) -> impl ::core::future::Future< 749 Output = wasmtime::component::__internal::Vec< 750 wasmtime::component::Resource<Bar>, 751 >, 752 > + Send { 753 async move { Host::list_result(*self).await } 754 } record_own_arg( &mut self, x: NestedOwn, ) -> impl ::core::future::Future<Output = ()> + Send755 fn record_own_arg( 756 &mut self, 757 x: NestedOwn, 758 ) -> impl ::core::future::Future<Output = ()> + Send { 759 async move { Host::record_own_arg(*self, x).await } 760 } record_borrow_arg( &mut self, x: NestedBorrow, ) -> impl ::core::future::Future<Output = ()> + Send761 fn record_borrow_arg( 762 &mut self, 763 x: NestedBorrow, 764 ) -> impl ::core::future::Future<Output = ()> + Send { 765 async move { Host::record_borrow_arg(*self, x).await } 766 } record_result( &mut self, ) -> impl ::core::future::Future<Output = NestedOwn> + Send767 fn record_result( 768 &mut self, 769 ) -> impl ::core::future::Future<Output = NestedOwn> + Send { 770 async move { Host::record_result(*self).await } 771 } func_with_handle_typedef( &mut self, x: SomeHandle, ) -> impl ::core::future::Future<Output = ()> + Send772 fn func_with_handle_typedef( 773 &mut self, 774 x: SomeHandle, 775 ) -> impl ::core::future::Future<Output = ()> + Send { 776 async move { Host::func_with_handle_typedef(*self, x).await } 777 } 778 } 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,779 pub fn add_to_linker<T, D>( 780 linker: &mut wasmtime::component::Linker<T>, 781 host_getter: fn(&mut T) -> D::Data<'_>, 782 ) -> wasmtime::Result<()> 783 where 784 D: HostWithStore, 785 for<'a> D::Data<'a>: Host, 786 T: 'static + Send, 787 { 788 let mut inst = linker.instance("foo:foo/resources")?; 789 inst.resource_async( 790 "bar", 791 wasmtime::component::ResourceType::host::<Bar>(), 792 move |mut store, rep| { 793 wasmtime::component::__internal::Box::new(async move { 794 wasmtime::ToWasmtimeResult::to_wasmtime_result( 795 HostBar::drop( 796 &mut host_getter(store.data_mut()), 797 wasmtime::component::Resource::new_own(rep), 798 ) 799 .await, 800 ) 801 }) 802 }, 803 )?; 804 inst.resource_async( 805 "fallible", 806 wasmtime::component::ResourceType::host::<Fallible>(), 807 move |mut store, rep| { 808 wasmtime::component::__internal::Box::new(async move { 809 wasmtime::ToWasmtimeResult::to_wasmtime_result( 810 HostFallible::drop( 811 &mut host_getter(store.data_mut()), 812 wasmtime::component::Resource::new_own(rep), 813 ) 814 .await, 815 ) 816 }) 817 }, 818 )?; 819 inst.func_wrap_async( 820 "[constructor]bar", 821 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 822 wasmtime::component::__internal::Box::new(async move { 823 let host = &mut host_getter(caller.data_mut()); 824 let r = HostBar::new(host).await; 825 Ok((r,)) 826 }) 827 }, 828 )?; 829 inst.func_wrap_async( 830 "[static]bar.static-a", 831 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 832 wasmtime::component::__internal::Box::new(async move { 833 let host = &mut host_getter(caller.data_mut()); 834 let r = HostBar::static_a(host).await; 835 Ok((r,)) 836 }) 837 }, 838 )?; 839 inst.func_wrap_async( 840 "[method]bar.method-a", 841 move | 842 mut caller: wasmtime::StoreContextMut<'_, T>, 843 (arg0,): (wasmtime::component::Resource<Bar>,)| 844 { 845 wasmtime::component::__internal::Box::new(async move { 846 let host = &mut host_getter(caller.data_mut()); 847 let r = HostBar::method_a(host, arg0).await; 848 Ok((r,)) 849 }) 850 }, 851 )?; 852 inst.func_wrap_async( 853 "bar-own-arg", 854 move | 855 mut caller: wasmtime::StoreContextMut<'_, T>, 856 (arg0,): (wasmtime::component::Resource<Bar>,)| 857 { 858 wasmtime::component::__internal::Box::new(async move { 859 let host = &mut host_getter(caller.data_mut()); 860 let r = Host::bar_own_arg(host, arg0).await; 861 Ok(r) 862 }) 863 }, 864 )?; 865 inst.func_wrap_async( 866 "bar-borrow-arg", 867 move | 868 mut caller: wasmtime::StoreContextMut<'_, T>, 869 (arg0,): (wasmtime::component::Resource<Bar>,)| 870 { 871 wasmtime::component::__internal::Box::new(async move { 872 let host = &mut host_getter(caller.data_mut()); 873 let r = Host::bar_borrow_arg(host, arg0).await; 874 Ok(r) 875 }) 876 }, 877 )?; 878 inst.func_wrap_async( 879 "bar-result", 880 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 881 wasmtime::component::__internal::Box::new(async move { 882 let host = &mut host_getter(caller.data_mut()); 883 let r = Host::bar_result(host).await; 884 Ok((r,)) 885 }) 886 }, 887 )?; 888 inst.func_wrap_async( 889 "tuple-own-arg", 890 move | 891 mut caller: wasmtime::StoreContextMut<'_, T>, 892 (arg0,): ((wasmtime::component::Resource<Bar>, u32),)| 893 { 894 wasmtime::component::__internal::Box::new(async move { 895 let host = &mut host_getter(caller.data_mut()); 896 let r = Host::tuple_own_arg(host, arg0).await; 897 Ok(r) 898 }) 899 }, 900 )?; 901 inst.func_wrap_async( 902 "tuple-borrow-arg", 903 move | 904 mut caller: wasmtime::StoreContextMut<'_, T>, 905 (arg0,): ((wasmtime::component::Resource<Bar>, u32),)| 906 { 907 wasmtime::component::__internal::Box::new(async move { 908 let host = &mut host_getter(caller.data_mut()); 909 let r = Host::tuple_borrow_arg(host, arg0).await; 910 Ok(r) 911 }) 912 }, 913 )?; 914 inst.func_wrap_async( 915 "tuple-result", 916 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 917 wasmtime::component::__internal::Box::new(async move { 918 let host = &mut host_getter(caller.data_mut()); 919 let r = Host::tuple_result(host).await; 920 Ok((r,)) 921 }) 922 }, 923 )?; 924 inst.func_wrap_async( 925 "option-own-arg", 926 move | 927 mut caller: wasmtime::StoreContextMut<'_, T>, 928 (arg0,): (Option<wasmtime::component::Resource<Bar>>,)| 929 { 930 wasmtime::component::__internal::Box::new(async move { 931 let host = &mut host_getter(caller.data_mut()); 932 let r = Host::option_own_arg(host, arg0).await; 933 Ok(r) 934 }) 935 }, 936 )?; 937 inst.func_wrap_async( 938 "option-borrow-arg", 939 move | 940 mut caller: wasmtime::StoreContextMut<'_, T>, 941 (arg0,): (Option<wasmtime::component::Resource<Bar>>,)| 942 { 943 wasmtime::component::__internal::Box::new(async move { 944 let host = &mut host_getter(caller.data_mut()); 945 let r = Host::option_borrow_arg(host, arg0).await; 946 Ok(r) 947 }) 948 }, 949 )?; 950 inst.func_wrap_async( 951 "option-result", 952 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 953 wasmtime::component::__internal::Box::new(async move { 954 let host = &mut host_getter(caller.data_mut()); 955 let r = Host::option_result(host).await; 956 Ok((r,)) 957 }) 958 }, 959 )?; 960 inst.func_wrap_async( 961 "result-own-arg", 962 move | 963 mut caller: wasmtime::StoreContextMut<'_, T>, 964 (arg0,): (Result<wasmtime::component::Resource<Bar>, ()>,)| 965 { 966 wasmtime::component::__internal::Box::new(async move { 967 let host = &mut host_getter(caller.data_mut()); 968 let r = Host::result_own_arg(host, arg0).await; 969 Ok(r) 970 }) 971 }, 972 )?; 973 inst.func_wrap_async( 974 "result-borrow-arg", 975 move | 976 mut caller: wasmtime::StoreContextMut<'_, T>, 977 (arg0,): (Result<wasmtime::component::Resource<Bar>, ()>,)| 978 { 979 wasmtime::component::__internal::Box::new(async move { 980 let host = &mut host_getter(caller.data_mut()); 981 let r = Host::result_borrow_arg(host, arg0).await; 982 Ok(r) 983 }) 984 }, 985 )?; 986 inst.func_wrap_async( 987 "result-result", 988 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 989 wasmtime::component::__internal::Box::new(async move { 990 let host = &mut host_getter(caller.data_mut()); 991 let r = Host::result_result(host).await; 992 Ok((r,)) 993 }) 994 }, 995 )?; 996 inst.func_wrap_async( 997 "list-own-arg", 998 move | 999 mut caller: wasmtime::StoreContextMut<'_, T>, 1000 ( 1001 arg0, 1002 ): ( 1003 wasmtime::component::__internal::Vec< 1004 wasmtime::component::Resource<Bar>, 1005 >, 1006 )| 1007 { 1008 wasmtime::component::__internal::Box::new(async move { 1009 let host = &mut host_getter(caller.data_mut()); 1010 let r = Host::list_own_arg(host, arg0).await; 1011 Ok(r) 1012 }) 1013 }, 1014 )?; 1015 inst.func_wrap_async( 1016 "list-borrow-arg", 1017 move | 1018 mut caller: wasmtime::StoreContextMut<'_, T>, 1019 ( 1020 arg0, 1021 ): ( 1022 wasmtime::component::__internal::Vec< 1023 wasmtime::component::Resource<Bar>, 1024 >, 1025 )| 1026 { 1027 wasmtime::component::__internal::Box::new(async move { 1028 let host = &mut host_getter(caller.data_mut()); 1029 let r = Host::list_borrow_arg(host, arg0).await; 1030 Ok(r) 1031 }) 1032 }, 1033 )?; 1034 inst.func_wrap_async( 1035 "list-result", 1036 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 1037 wasmtime::component::__internal::Box::new(async move { 1038 let host = &mut host_getter(caller.data_mut()); 1039 let r = Host::list_result(host).await; 1040 Ok((r,)) 1041 }) 1042 }, 1043 )?; 1044 inst.func_wrap_async( 1045 "record-own-arg", 1046 move | 1047 mut caller: wasmtime::StoreContextMut<'_, T>, 1048 (arg0,): (NestedOwn,)| 1049 { 1050 wasmtime::component::__internal::Box::new(async move { 1051 let host = &mut host_getter(caller.data_mut()); 1052 let r = Host::record_own_arg(host, arg0).await; 1053 Ok(r) 1054 }) 1055 }, 1056 )?; 1057 inst.func_wrap_async( 1058 "record-borrow-arg", 1059 move | 1060 mut caller: wasmtime::StoreContextMut<'_, T>, 1061 (arg0,): (NestedBorrow,)| 1062 { 1063 wasmtime::component::__internal::Box::new(async move { 1064 let host = &mut host_getter(caller.data_mut()); 1065 let r = Host::record_borrow_arg(host, arg0).await; 1066 Ok(r) 1067 }) 1068 }, 1069 )?; 1070 inst.func_wrap_async( 1071 "record-result", 1072 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 1073 wasmtime::component::__internal::Box::new(async move { 1074 let host = &mut host_getter(caller.data_mut()); 1075 let r = Host::record_result(host).await; 1076 Ok((r,)) 1077 }) 1078 }, 1079 )?; 1080 inst.func_wrap_async( 1081 "func-with-handle-typedef", 1082 move | 1083 mut caller: wasmtime::StoreContextMut<'_, T>, 1084 (arg0,): (SomeHandle,)| 1085 { 1086 wasmtime::component::__internal::Box::new(async move { 1087 let host = &mut host_getter(caller.data_mut()); 1088 let r = Host::func_with_handle_typedef(host, arg0).await; 1089 Ok(r) 1090 }) 1091 }, 1092 )?; 1093 inst.func_wrap_async( 1094 "[constructor]fallible", 1095 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 1096 wasmtime::component::__internal::Box::new(async move { 1097 let host = &mut host_getter(caller.data_mut()); 1098 let r = HostFallible::new(host).await; 1099 Ok((r,)) 1100 }) 1101 }, 1102 )?; 1103 Ok(()) 1104 } 1105 } 1106 #[allow(clippy::all)] 1107 pub mod long_use_chain1 { 1108 #[allow(unused_imports)] 1109 use wasmtime::component::__internal::Box; 1110 pub enum A {} 1111 pub trait HostAWithStore: wasmtime::component::HasData {} 1112 impl<_T: ?Sized> HostAWithStore for _T 1113 where 1114 _T: wasmtime::component::HasData, 1115 {} 1116 pub trait HostA { drop( &mut self, rep: wasmtime::component::Resource<A>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send1117 fn drop( 1118 &mut self, 1119 rep: wasmtime::component::Resource<A>, 1120 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 1121 } 1122 impl<_T: HostA + ?Sized + Send> HostA for &mut _T { drop( &mut self, rep: wasmtime::component::Resource<A>, ) -> wasmtime::Result<()>1123 async fn drop( 1124 &mut self, 1125 rep: wasmtime::component::Resource<A>, 1126 ) -> wasmtime::Result<()> { 1127 HostA::drop(*self, rep).await 1128 } 1129 } 1130 pub trait HostWithStore: wasmtime::component::HasData + HostAWithStore + Send {} 1131 impl<_T: ?Sized> HostWithStore for _T 1132 where 1133 _T: wasmtime::component::HasData + HostAWithStore + Send, 1134 {} 1135 pub trait Host: HostA + Send {} 1136 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,1137 pub fn add_to_linker<T, D>( 1138 linker: &mut wasmtime::component::Linker<T>, 1139 host_getter: fn(&mut T) -> D::Data<'_>, 1140 ) -> wasmtime::Result<()> 1141 where 1142 D: HostWithStore, 1143 for<'a> D::Data<'a>: Host, 1144 T: 'static + Send, 1145 { 1146 let mut inst = linker.instance("foo:foo/long-use-chain1")?; 1147 inst.resource_async( 1148 "a", 1149 wasmtime::component::ResourceType::host::<A>(), 1150 move |mut store, rep| { 1151 wasmtime::component::__internal::Box::new(async move { 1152 wasmtime::ToWasmtimeResult::to_wasmtime_result( 1153 HostA::drop( 1154 &mut host_getter(store.data_mut()), 1155 wasmtime::component::Resource::new_own(rep), 1156 ) 1157 .await, 1158 ) 1159 }) 1160 }, 1161 )?; 1162 Ok(()) 1163 } 1164 } 1165 #[allow(clippy::all)] 1166 pub mod long_use_chain2 { 1167 #[allow(unused_imports)] 1168 use wasmtime::component::__internal::Box; 1169 pub type A = super::super::super::foo::foo::long_use_chain1::A; 1170 pub trait HostWithStore: wasmtime::component::HasData {} 1171 impl<_T: ?Sized> HostWithStore for _T 1172 where 1173 _T: wasmtime::component::HasData, 1174 {} 1175 pub trait Host {} 1176 impl<_T: Host + ?Sized> 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,1177 pub fn add_to_linker<T, D>( 1178 linker: &mut wasmtime::component::Linker<T>, 1179 host_getter: fn(&mut T) -> D::Data<'_>, 1180 ) -> wasmtime::Result<()> 1181 where 1182 D: HostWithStore, 1183 for<'a> D::Data<'a>: Host, 1184 T: 'static, 1185 { 1186 let mut inst = linker.instance("foo:foo/long-use-chain2")?; 1187 Ok(()) 1188 } 1189 } 1190 #[allow(clippy::all)] 1191 pub mod long_use_chain3 { 1192 #[allow(unused_imports)] 1193 use wasmtime::component::__internal::Box; 1194 pub type A = super::super::super::foo::foo::long_use_chain2::A; 1195 pub trait HostWithStore: wasmtime::component::HasData {} 1196 impl<_T: ?Sized> HostWithStore for _T 1197 where 1198 _T: wasmtime::component::HasData, 1199 {} 1200 pub trait Host {} 1201 impl<_T: Host + ?Sized> 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,1202 pub fn add_to_linker<T, D>( 1203 linker: &mut wasmtime::component::Linker<T>, 1204 host_getter: fn(&mut T) -> D::Data<'_>, 1205 ) -> wasmtime::Result<()> 1206 where 1207 D: HostWithStore, 1208 for<'a> D::Data<'a>: Host, 1209 T: 'static, 1210 { 1211 let mut inst = linker.instance("foo:foo/long-use-chain3")?; 1212 Ok(()) 1213 } 1214 } 1215 #[allow(clippy::all)] 1216 pub mod long_use_chain4 { 1217 #[allow(unused_imports)] 1218 use wasmtime::component::__internal::Box; 1219 pub type A = super::super::super::foo::foo::long_use_chain3::A; 1220 pub trait HostWithStore: wasmtime::component::HasData + Send {} 1221 impl<_T: ?Sized> HostWithStore for _T 1222 where 1223 _T: wasmtime::component::HasData + Send, 1224 {} 1225 pub trait Host: Send { foo( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<A>, > + Send1226 fn foo( 1227 &mut self, 1228 ) -> impl ::core::future::Future< 1229 Output = wasmtime::component::Resource<A>, 1230 > + Send; 1231 } 1232 impl<_T: Host + ?Sized + Send> Host for &mut _T { foo( &mut self, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource<A>, > + Send1233 fn foo( 1234 &mut self, 1235 ) -> impl ::core::future::Future< 1236 Output = wasmtime::component::Resource<A>, 1237 > + Send { 1238 async move { Host::foo(*self).await } 1239 } 1240 } 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,1241 pub fn add_to_linker<T, D>( 1242 linker: &mut wasmtime::component::Linker<T>, 1243 host_getter: fn(&mut T) -> D::Data<'_>, 1244 ) -> wasmtime::Result<()> 1245 where 1246 D: HostWithStore, 1247 for<'a> D::Data<'a>: Host, 1248 T: 'static + Send, 1249 { 1250 let mut inst = linker.instance("foo:foo/long-use-chain4")?; 1251 inst.func_wrap_async( 1252 "foo", 1253 move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 1254 wasmtime::component::__internal::Box::new(async move { 1255 let host = &mut host_getter(caller.data_mut()); 1256 let r = Host::foo(host).await; 1257 Ok((r,)) 1258 }) 1259 }, 1260 )?; 1261 Ok(()) 1262 } 1263 } 1264 #[allow(clippy::all)] 1265 pub mod transitive_interface_with_resource { 1266 #[allow(unused_imports)] 1267 use wasmtime::component::__internal::Box; 1268 pub enum Foo {} 1269 pub trait HostFooWithStore: wasmtime::component::HasData {} 1270 impl<_T: ?Sized> HostFooWithStore for _T 1271 where 1272 _T: wasmtime::component::HasData, 1273 {} 1274 pub trait HostFoo { drop( &mut self, rep: wasmtime::component::Resource<Foo>, ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send1275 fn drop( 1276 &mut self, 1277 rep: wasmtime::component::Resource<Foo>, 1278 ) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send; 1279 } 1280 impl<_T: HostFoo + ?Sized + Send> HostFoo for &mut _T { drop( &mut self, rep: wasmtime::component::Resource<Foo>, ) -> wasmtime::Result<()>1281 async fn drop( 1282 &mut self, 1283 rep: wasmtime::component::Resource<Foo>, 1284 ) -> wasmtime::Result<()> { 1285 HostFoo::drop(*self, rep).await 1286 } 1287 } 1288 pub trait HostWithStore: wasmtime::component::HasData + HostFooWithStore + Send {} 1289 impl<_T: ?Sized> HostWithStore for _T 1290 where 1291 _T: wasmtime::component::HasData + HostFooWithStore + Send, 1292 {} 1293 pub trait Host: HostFoo + Send {} 1294 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,1295 pub fn add_to_linker<T, D>( 1296 linker: &mut wasmtime::component::Linker<T>, 1297 host_getter: fn(&mut T) -> D::Data<'_>, 1298 ) -> wasmtime::Result<()> 1299 where 1300 D: HostWithStore, 1301 for<'a> D::Data<'a>: Host, 1302 T: 'static + Send, 1303 { 1304 let mut inst = linker 1305 .instance("foo:foo/transitive-interface-with-resource")?; 1306 inst.resource_async( 1307 "foo", 1308 wasmtime::component::ResourceType::host::<Foo>(), 1309 move |mut store, rep| { 1310 wasmtime::component::__internal::Box::new(async move { 1311 wasmtime::ToWasmtimeResult::to_wasmtime_result( 1312 HostFoo::drop( 1313 &mut host_getter(store.data_mut()), 1314 wasmtime::component::Resource::new_own(rep), 1315 ) 1316 .await, 1317 ) 1318 }) 1319 }, 1320 )?; 1321 Ok(()) 1322 } 1323 } 1324 } 1325 } 1326 pub mod exports { 1327 pub mod foo { 1328 pub mod foo { 1329 #[allow(clippy::all)] 1330 pub mod uses_resource_transitively { 1331 #[allow(unused_imports)] 1332 use wasmtime::component::__internal::Box; 1333 pub type Foo = super::super::super::super::foo::foo::transitive_interface_with_resource::Foo; 1334 #[derive(Clone)] 1335 pub struct Guest { 1336 handle: wasmtime::component::Func, 1337 } 1338 #[derive(Clone)] 1339 pub struct GuestIndices { 1340 handle: wasmtime::component::ComponentExportIndex, 1341 } 1342 impl GuestIndices { 1343 /// Constructor for [`GuestIndices`] which takes a 1344 /// [`Component`](wasmtime::component::Component) as input and can be executed 1345 /// before instantiation. 1346 /// 1347 /// This constructor can be used to front-load string lookups to find exports 1348 /// within a component. new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<GuestIndices>1349 pub fn new<_T>( 1350 _instance_pre: &wasmtime::component::InstancePre<_T>, 1351 ) -> wasmtime::Result<GuestIndices> { 1352 let instance = _instance_pre 1353 .component() 1354 .get_export_index(None, "foo:foo/uses-resource-transitively") 1355 .ok_or_else(|| { 1356 wasmtime::format_err!( 1357 "no exported instance named `foo:foo/uses-resource-transitively`" 1358 ) 1359 })?; 1360 let mut lookup = move |name| { 1361 _instance_pre 1362 .component() 1363 .get_export_index(Some(&instance), name) 1364 .ok_or_else(|| { 1365 wasmtime::format_err!( 1366 "instance export `foo:foo/uses-resource-transitively` does \ 1367 not have export `{name}`" 1368 ) 1369 }) 1370 }; 1371 let _ = &mut lookup; 1372 let handle = lookup("handle")?; 1373 Ok(GuestIndices { handle }) 1374 } load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Guest>1375 pub fn load( 1376 &self, 1377 mut store: impl wasmtime::AsContextMut, 1378 instance: &wasmtime::component::Instance, 1379 ) -> wasmtime::Result<Guest> { 1380 let _instance = instance; 1381 let _instance_pre = _instance.instance_pre(&store); 1382 let _instance_type = _instance_pre.instance_type(); 1383 let mut store = store.as_context_mut(); 1384 let _ = &mut store; 1385 let handle = *_instance 1386 .get_typed_func::< 1387 (wasmtime::component::Resource<Foo>,), 1388 (), 1389 >(&mut store, &self.handle)? 1390 .func(); 1391 Ok(Guest { handle }) 1392 } 1393 } 1394 impl Guest { call_handle<S: wasmtime::AsContextMut>( &self, mut store: S, arg0: wasmtime::component::Resource<Foo>, ) -> wasmtime::Result<()> where <S as wasmtime::AsContext>::Data: Send,1395 pub async fn call_handle<S: wasmtime::AsContextMut>( 1396 &self, 1397 mut store: S, 1398 arg0: wasmtime::component::Resource<Foo>, 1399 ) -> wasmtime::Result<()> 1400 where 1401 <S as wasmtime::AsContext>::Data: Send, 1402 { 1403 let callee = unsafe { 1404 wasmtime::component::TypedFunc::< 1405 (wasmtime::component::Resource<Foo>,), 1406 (), 1407 >::new_unchecked(self.handle) 1408 }; 1409 let () = callee 1410 .call_async(store.as_context_mut(), (arg0,)) 1411 .await?; 1412 Ok(()) 1413 } 1414 } 1415 } 1416 } 1417 } 1418 } 1419