1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// component which implements the world `the-flags`. 3 /// 4 /// This structure is created through [`TheFlagsPre::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 [`TheFlags`] as well. 9 pub struct TheFlagsPre<T> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: TheFlagsIndices, 12 } 13 impl<T> Clone for TheFlagsPre<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> TheFlagsPre<_T> { 22 /// Creates a new copy of `TheFlagsPre` 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 = TheFlagsIndices::new(instance_pre.component())?; 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 [`TheFlags`] 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<TheFlags> 50 where 51 _T: Send + 'static, 52 { 53 let mut store = store.as_context_mut(); 54 let instance = self.instance_pre.instantiate_async(&mut store).await?; 55 self.indices.load(&mut store, &instance) 56 } 57 } 58 /// Auto-generated bindings for index of the exports of 59 /// `the-flags`. 60 /// 61 /// This is an implementation detail of [`TheFlagsPre`] and can 62 /// be constructed if needed as well. 63 /// 64 /// For more information see [`TheFlags`] as well. 65 #[derive(Clone)] 66 pub struct TheFlagsIndices { 67 interface0: exports::foo::foo::flegs::GuestIndices, 68 } 69 /// Auto-generated bindings for an instance a component which 70 /// implements the world `the-flags`. 71 /// 72 /// This structure can be created through a number of means 73 /// depending on your requirements and what you have on hand: 74 /// 75 /// * The most convenient way is to use 76 /// [`TheFlags::instantiate_async`] which only needs a 77 /// [`Store`], [`Component`], and [`Linker`]. 78 /// 79 /// * Alternatively you can create a [`TheFlagsPre`] ahead of 80 /// time with a [`Component`] to front-load string lookups 81 /// of exports once instead of per-instantiation. This 82 /// method then uses [`TheFlagsPre::instantiate_async`] to 83 /// create a [`TheFlags`]. 84 /// 85 /// * If you've instantiated the instance yourself already 86 /// then you can use [`TheFlags::new`]. 87 /// 88 /// * You can also access the guts of instantiation through 89 /// [`TheFlagsIndices::new_instance`] followed 90 /// by [`TheFlagsIndices::load`] to crate an instance of this 91 /// type. 92 /// 93 /// These methods are all equivalent to one another and move 94 /// around the tradeoff of what work is performed when. 95 /// 96 /// [`Store`]: wasmtime::Store 97 /// [`Component`]: wasmtime::component::Component 98 /// [`Linker`]: wasmtime::component::Linker 99 pub struct TheFlags { 100 interface0: exports::foo::foo::flegs::Guest, 101 } 102 const _: () = { 103 #[allow(unused_imports)] 104 use wasmtime::component::__internal::anyhow; 105 impl TheFlagsIndices { 106 /// Creates a new copy of `TheFlagsIndices` bindings which can then 107 /// be used to instantiate into a particular store. 108 /// 109 /// This method may fail if the component does not have the 110 /// required exports. 111 pub fn new( 112 component: &wasmtime::component::Component, 113 ) -> wasmtime::Result<Self> { 114 let _component = component; 115 let interface0 = exports::foo::foo::flegs::GuestIndices::new(_component)?; 116 Ok(TheFlagsIndices { interface0 }) 117 } 118 /// Creates a new instance of [`TheFlagsIndices`] from an 119 /// instantiated component. 120 /// 121 /// This method of creating a [`TheFlags`] will perform string 122 /// lookups for all exports when this method is called. This 123 /// will only succeed if the provided instance matches the 124 /// requirements of [`TheFlags`]. 125 pub fn new_instance( 126 mut store: impl wasmtime::AsContextMut, 127 instance: &wasmtime::component::Instance, 128 ) -> wasmtime::Result<Self> { 129 let _instance = instance; 130 let interface0 = exports::foo::foo::flegs::GuestIndices::new_instance( 131 &mut store, 132 _instance, 133 )?; 134 Ok(TheFlagsIndices { interface0 }) 135 } 136 /// Uses the indices stored in `self` to load an instance 137 /// of [`TheFlags`] 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<TheFlags> { 146 let _instance = instance; 147 let interface0 = self.interface0.load(&mut store, &_instance)?; 148 Ok(TheFlags { interface0 }) 149 } 150 } 151 impl TheFlags { 152 /// Convenience wrapper around [`TheFlagsPre::new`] and 153 /// [`TheFlagsPre::instantiate_async`]. 154 pub async fn instantiate_async<_T>( 155 mut store: impl wasmtime::AsContextMut<Data = _T>, 156 component: &wasmtime::component::Component, 157 linker: &wasmtime::component::Linker<_T>, 158 ) -> wasmtime::Result<TheFlags> 159 where 160 _T: Send + 'static, 161 { 162 let pre = linker.instantiate_pre(component)?; 163 TheFlagsPre::new(pre)?.instantiate_async(store).await 164 } 165 /// Convenience wrapper around [`TheFlagsIndices::new_instance`] and 166 /// [`TheFlagsIndices::load`]. 167 pub fn new( 168 mut store: impl wasmtime::AsContextMut, 169 instance: &wasmtime::component::Instance, 170 ) -> wasmtime::Result<TheFlags> { 171 let indices = TheFlagsIndices::new_instance(&mut store, instance)?; 172 indices.load(store, instance) 173 } 174 pub fn add_to_linker<T, U>( 175 linker: &mut wasmtime::component::Linker<T>, 176 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 177 ) -> wasmtime::Result<()> 178 where 179 T: Send + foo::foo::flegs::Host<Data = T> + 'static, 180 U: Send + foo::foo::flegs::Host<Data = T>, 181 { 182 foo::foo::flegs::add_to_linker(linker, get)?; 183 Ok(()) 184 } 185 pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest { 186 &self.interface0 187 } 188 } 189 }; 190 pub mod foo { 191 pub mod foo { 192 #[allow(clippy::all)] 193 pub mod flegs { 194 #[allow(unused_imports)] 195 use wasmtime::component::__internal::{anyhow, Box}; 196 wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; }); 197 const _: () = { 198 assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32); 199 assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32); 200 }; 201 wasmtime::component::flags!( 202 Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")] 203 const B1; } 204 ); 205 const _: () = { 206 assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32); 207 assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32); 208 }; 209 wasmtime::component::flags!( 210 Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")] 211 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 212 const B3; } 213 ); 214 const _: () = { 215 assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32); 216 assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32); 217 }; 218 wasmtime::component::flags!( 219 Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")] 220 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 221 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 222 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 223 const B7; } 224 ); 225 const _: () = { 226 assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32); 227 assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32); 228 }; 229 wasmtime::component::flags!( 230 Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")] 231 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 232 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 233 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 234 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 235 const B9; #[component(name = "b10")] const B10; #[component(name = 236 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 237 = "b13")] const B13; #[component(name = "b14")] const B14; 238 #[component(name = "b15")] const B15; } 239 ); 240 const _: () = { 241 assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32); 242 assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32); 243 }; 244 wasmtime::component::flags!( 245 Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")] 246 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 247 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 248 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 249 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 250 const B9; #[component(name = "b10")] const B10; #[component(name = 251 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 252 = "b13")] const B13; #[component(name = "b14")] const B14; 253 #[component(name = "b15")] const B15; #[component(name = "b16")] const 254 B16; #[component(name = "b17")] const B17; #[component(name = "b18")] 255 const B18; #[component(name = "b19")] const B19; #[component(name = 256 "b20")] const B20; #[component(name = "b21")] const B21; #[component(name 257 = "b22")] const B22; #[component(name = "b23")] const B23; 258 #[component(name = "b24")] const B24; #[component(name = "b25")] const 259 B25; #[component(name = "b26")] const B26; #[component(name = "b27")] 260 const B27; #[component(name = "b28")] const B28; #[component(name = 261 "b29")] const B29; #[component(name = "b30")] const B30; #[component(name 262 = "b31")] const B31; } 263 ); 264 const _: () = { 265 assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32); 266 assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32); 267 }; 268 wasmtime::component::flags!( 269 Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")] 270 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 271 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 272 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 273 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 274 const B9; #[component(name = "b10")] const B10; #[component(name = 275 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 276 = "b13")] const B13; #[component(name = "b14")] const B14; 277 #[component(name = "b15")] const B15; #[component(name = "b16")] const 278 B16; #[component(name = "b17")] const B17; #[component(name = "b18")] 279 const B18; #[component(name = "b19")] const B19; #[component(name = 280 "b20")] const B20; #[component(name = "b21")] const B21; #[component(name 281 = "b22")] const B22; #[component(name = "b23")] const B23; 282 #[component(name = "b24")] const B24; #[component(name = "b25")] const 283 B25; #[component(name = "b26")] const B26; #[component(name = "b27")] 284 const B27; #[component(name = "b28")] const B28; #[component(name = 285 "b29")] const B29; #[component(name = "b30")] const B30; #[component(name 286 = "b31")] const B31; #[component(name = "b32")] const B32; 287 #[component(name = "b33")] const B33; #[component(name = "b34")] const 288 B34; #[component(name = "b35")] const B35; #[component(name = "b36")] 289 const B36; #[component(name = "b37")] const B37; #[component(name = 290 "b38")] const B38; #[component(name = "b39")] const B39; #[component(name 291 = "b40")] const B40; #[component(name = "b41")] const B41; 292 #[component(name = "b42")] const B42; #[component(name = "b43")] const 293 B43; #[component(name = "b44")] const B44; #[component(name = "b45")] 294 const B45; #[component(name = "b46")] const B46; #[component(name = 295 "b47")] const B47; #[component(name = "b48")] const B48; #[component(name 296 = "b49")] const B49; #[component(name = "b50")] const B50; 297 #[component(name = "b51")] const B51; #[component(name = "b52")] const 298 B52; #[component(name = "b53")] const B53; #[component(name = "b54")] 299 const B54; #[component(name = "b55")] const B55; #[component(name = 300 "b56")] const B56; #[component(name = "b57")] const B57; #[component(name 301 = "b58")] const B58; #[component(name = "b59")] const B59; 302 #[component(name = "b60")] const B60; #[component(name = "b61")] const 303 B61; #[component(name = "b62")] const B62; #[component(name = "b63")] 304 const B63; } 305 ); 306 const _: () = { 307 assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32); 308 assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32); 309 }; 310 pub trait Host { 311 type Data; 312 fn roundtrip_flag1( 313 store: wasmtime::StoreContextMut<'_, Self::Data>, 314 x: Flag1, 315 ) -> impl ::core::future::Future< 316 Output = impl FnOnce( 317 wasmtime::StoreContextMut<'_, Self::Data>, 318 ) -> Flag1 + Send + Sync + 'static, 319 > + Send + Sync + 'static 320 where 321 Self: Sized; 322 fn roundtrip_flag2( 323 store: wasmtime::StoreContextMut<'_, Self::Data>, 324 x: Flag2, 325 ) -> impl ::core::future::Future< 326 Output = impl FnOnce( 327 wasmtime::StoreContextMut<'_, Self::Data>, 328 ) -> Flag2 + Send + Sync + 'static, 329 > + Send + Sync + 'static 330 where 331 Self: Sized; 332 fn roundtrip_flag4( 333 store: wasmtime::StoreContextMut<'_, Self::Data>, 334 x: Flag4, 335 ) -> impl ::core::future::Future< 336 Output = impl FnOnce( 337 wasmtime::StoreContextMut<'_, Self::Data>, 338 ) -> Flag4 + Send + Sync + 'static, 339 > + Send + Sync + 'static 340 where 341 Self: Sized; 342 fn roundtrip_flag8( 343 store: wasmtime::StoreContextMut<'_, Self::Data>, 344 x: Flag8, 345 ) -> impl ::core::future::Future< 346 Output = impl FnOnce( 347 wasmtime::StoreContextMut<'_, Self::Data>, 348 ) -> Flag8 + Send + Sync + 'static, 349 > + Send + Sync + 'static 350 where 351 Self: Sized; 352 fn roundtrip_flag16( 353 store: wasmtime::StoreContextMut<'_, Self::Data>, 354 x: Flag16, 355 ) -> impl ::core::future::Future< 356 Output = impl FnOnce( 357 wasmtime::StoreContextMut<'_, Self::Data>, 358 ) -> Flag16 + Send + Sync + 'static, 359 > + Send + Sync + 'static 360 where 361 Self: Sized; 362 fn roundtrip_flag32( 363 store: wasmtime::StoreContextMut<'_, Self::Data>, 364 x: Flag32, 365 ) -> impl ::core::future::Future< 366 Output = impl FnOnce( 367 wasmtime::StoreContextMut<'_, Self::Data>, 368 ) -> Flag32 + Send + Sync + 'static, 369 > + Send + Sync + 'static 370 where 371 Self: Sized; 372 fn roundtrip_flag64( 373 store: wasmtime::StoreContextMut<'_, Self::Data>, 374 x: Flag64, 375 ) -> impl ::core::future::Future< 376 Output = impl FnOnce( 377 wasmtime::StoreContextMut<'_, Self::Data>, 378 ) -> Flag64 + Send + Sync + 'static, 379 > + Send + Sync + 'static 380 where 381 Self: Sized; 382 } 383 pub trait GetHost< 384 T, 385 D, 386 >: Fn(T) -> <Self as GetHost<T, D>>::Host + Send + Sync + Copy + 'static { 387 type Host: Host<Data = D> + Send; 388 } 389 impl<F, T, D, O> GetHost<T, D> for F 390 where 391 F: Fn(T) -> O + Send + Sync + Copy + 'static, 392 O: Host<Data = D> + Send, 393 { 394 type Host = O; 395 } 396 pub fn add_to_linker_get_host< 397 T, 398 G: for<'a> GetHost<&'a mut T, T, Host: Host<Data = T> + Send>, 399 >( 400 linker: &mut wasmtime::component::Linker<T>, 401 host_getter: G, 402 ) -> wasmtime::Result<()> 403 where 404 T: Send + 'static, 405 { 406 let mut inst = linker.instance("foo:foo/flegs")?; 407 inst.func_wrap_concurrent( 408 "roundtrip-flag1", 409 move | 410 mut caller: wasmtime::StoreContextMut<'_, T>, 411 (arg0,): (Flag1,)| 412 { 413 let host = caller; 414 let r = <G::Host as Host>::roundtrip_flag1(host, arg0); 415 Box::pin(async move { 416 let fun = r.await; 417 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 418 let r = fun(caller); 419 Ok((r,)) 420 }) 421 as Box< 422 dyn FnOnce( 423 wasmtime::StoreContextMut<'_, T>, 424 ) -> wasmtime::Result<(Flag1,)> + Send + Sync, 425 > 426 }) 427 as ::core::pin::Pin< 428 Box< 429 dyn ::core::future::Future< 430 Output = Box< 431 dyn FnOnce( 432 wasmtime::StoreContextMut<'_, T>, 433 ) -> wasmtime::Result<(Flag1,)> + Send + Sync, 434 >, 435 > + Send + Sync + 'static, 436 >, 437 > 438 }, 439 )?; 440 inst.func_wrap_concurrent( 441 "roundtrip-flag2", 442 move | 443 mut caller: wasmtime::StoreContextMut<'_, T>, 444 (arg0,): (Flag2,)| 445 { 446 let host = caller; 447 let r = <G::Host as Host>::roundtrip_flag2(host, arg0); 448 Box::pin(async move { 449 let fun = r.await; 450 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 451 let r = fun(caller); 452 Ok((r,)) 453 }) 454 as Box< 455 dyn FnOnce( 456 wasmtime::StoreContextMut<'_, T>, 457 ) -> wasmtime::Result<(Flag2,)> + Send + Sync, 458 > 459 }) 460 as ::core::pin::Pin< 461 Box< 462 dyn ::core::future::Future< 463 Output = Box< 464 dyn FnOnce( 465 wasmtime::StoreContextMut<'_, T>, 466 ) -> wasmtime::Result<(Flag2,)> + Send + Sync, 467 >, 468 > + Send + Sync + 'static, 469 >, 470 > 471 }, 472 )?; 473 inst.func_wrap_concurrent( 474 "roundtrip-flag4", 475 move | 476 mut caller: wasmtime::StoreContextMut<'_, T>, 477 (arg0,): (Flag4,)| 478 { 479 let host = caller; 480 let r = <G::Host as Host>::roundtrip_flag4(host, arg0); 481 Box::pin(async move { 482 let fun = r.await; 483 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 484 let r = fun(caller); 485 Ok((r,)) 486 }) 487 as Box< 488 dyn FnOnce( 489 wasmtime::StoreContextMut<'_, T>, 490 ) -> wasmtime::Result<(Flag4,)> + Send + Sync, 491 > 492 }) 493 as ::core::pin::Pin< 494 Box< 495 dyn ::core::future::Future< 496 Output = Box< 497 dyn FnOnce( 498 wasmtime::StoreContextMut<'_, T>, 499 ) -> wasmtime::Result<(Flag4,)> + Send + Sync, 500 >, 501 > + Send + Sync + 'static, 502 >, 503 > 504 }, 505 )?; 506 inst.func_wrap_concurrent( 507 "roundtrip-flag8", 508 move | 509 mut caller: wasmtime::StoreContextMut<'_, T>, 510 (arg0,): (Flag8,)| 511 { 512 let host = caller; 513 let r = <G::Host as Host>::roundtrip_flag8(host, arg0); 514 Box::pin(async move { 515 let fun = r.await; 516 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 517 let r = fun(caller); 518 Ok((r,)) 519 }) 520 as Box< 521 dyn FnOnce( 522 wasmtime::StoreContextMut<'_, T>, 523 ) -> wasmtime::Result<(Flag8,)> + Send + Sync, 524 > 525 }) 526 as ::core::pin::Pin< 527 Box< 528 dyn ::core::future::Future< 529 Output = Box< 530 dyn FnOnce( 531 wasmtime::StoreContextMut<'_, T>, 532 ) -> wasmtime::Result<(Flag8,)> + Send + Sync, 533 >, 534 > + Send + Sync + 'static, 535 >, 536 > 537 }, 538 )?; 539 inst.func_wrap_concurrent( 540 "roundtrip-flag16", 541 move | 542 mut caller: wasmtime::StoreContextMut<'_, T>, 543 (arg0,): (Flag16,)| 544 { 545 let host = caller; 546 let r = <G::Host as Host>::roundtrip_flag16(host, arg0); 547 Box::pin(async move { 548 let fun = r.await; 549 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 550 let r = fun(caller); 551 Ok((r,)) 552 }) 553 as Box< 554 dyn FnOnce( 555 wasmtime::StoreContextMut<'_, T>, 556 ) -> wasmtime::Result<(Flag16,)> + Send + Sync, 557 > 558 }) 559 as ::core::pin::Pin< 560 Box< 561 dyn ::core::future::Future< 562 Output = Box< 563 dyn FnOnce( 564 wasmtime::StoreContextMut<'_, T>, 565 ) -> wasmtime::Result<(Flag16,)> + Send + Sync, 566 >, 567 > + Send + Sync + 'static, 568 >, 569 > 570 }, 571 )?; 572 inst.func_wrap_concurrent( 573 "roundtrip-flag32", 574 move | 575 mut caller: wasmtime::StoreContextMut<'_, T>, 576 (arg0,): (Flag32,)| 577 { 578 let host = caller; 579 let r = <G::Host as Host>::roundtrip_flag32(host, arg0); 580 Box::pin(async move { 581 let fun = r.await; 582 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 583 let r = fun(caller); 584 Ok((r,)) 585 }) 586 as Box< 587 dyn FnOnce( 588 wasmtime::StoreContextMut<'_, T>, 589 ) -> wasmtime::Result<(Flag32,)> + Send + Sync, 590 > 591 }) 592 as ::core::pin::Pin< 593 Box< 594 dyn ::core::future::Future< 595 Output = Box< 596 dyn FnOnce( 597 wasmtime::StoreContextMut<'_, T>, 598 ) -> wasmtime::Result<(Flag32,)> + Send + Sync, 599 >, 600 > + Send + Sync + 'static, 601 >, 602 > 603 }, 604 )?; 605 inst.func_wrap_concurrent( 606 "roundtrip-flag64", 607 move | 608 mut caller: wasmtime::StoreContextMut<'_, T>, 609 (arg0,): (Flag64,)| 610 { 611 let host = caller; 612 let r = <G::Host as Host>::roundtrip_flag64(host, arg0); 613 Box::pin(async move { 614 let fun = r.await; 615 Box::new(move |mut caller: wasmtime::StoreContextMut<'_, T>| { 616 let r = fun(caller); 617 Ok((r,)) 618 }) 619 as Box< 620 dyn FnOnce( 621 wasmtime::StoreContextMut<'_, T>, 622 ) -> wasmtime::Result<(Flag64,)> + Send + Sync, 623 > 624 }) 625 as ::core::pin::Pin< 626 Box< 627 dyn ::core::future::Future< 628 Output = Box< 629 dyn FnOnce( 630 wasmtime::StoreContextMut<'_, T>, 631 ) -> wasmtime::Result<(Flag64,)> + Send + Sync, 632 >, 633 > + Send + Sync + 'static, 634 >, 635 > 636 }, 637 )?; 638 Ok(()) 639 } 640 pub fn add_to_linker<T, U>( 641 linker: &mut wasmtime::component::Linker<T>, 642 get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, 643 ) -> wasmtime::Result<()> 644 where 645 U: Host<Data = T> + Send, 646 T: Send + 'static, 647 { 648 add_to_linker_get_host(linker, get) 649 } 650 impl<_T: Host> Host for &mut _T { 651 type Data = _T::Data; 652 fn roundtrip_flag1( 653 store: wasmtime::StoreContextMut<'_, Self::Data>, 654 x: Flag1, 655 ) -> impl ::core::future::Future< 656 Output = impl FnOnce( 657 wasmtime::StoreContextMut<'_, Self::Data>, 658 ) -> Flag1 + Send + Sync + 'static, 659 > + Send + Sync + 'static 660 where 661 Self: Sized, 662 { 663 <_T as Host>::roundtrip_flag1(store, x) 664 } 665 fn roundtrip_flag2( 666 store: wasmtime::StoreContextMut<'_, Self::Data>, 667 x: Flag2, 668 ) -> impl ::core::future::Future< 669 Output = impl FnOnce( 670 wasmtime::StoreContextMut<'_, Self::Data>, 671 ) -> Flag2 + Send + Sync + 'static, 672 > + Send + Sync + 'static 673 where 674 Self: Sized, 675 { 676 <_T as Host>::roundtrip_flag2(store, x) 677 } 678 fn roundtrip_flag4( 679 store: wasmtime::StoreContextMut<'_, Self::Data>, 680 x: Flag4, 681 ) -> impl ::core::future::Future< 682 Output = impl FnOnce( 683 wasmtime::StoreContextMut<'_, Self::Data>, 684 ) -> Flag4 + Send + Sync + 'static, 685 > + Send + Sync + 'static 686 where 687 Self: Sized, 688 { 689 <_T as Host>::roundtrip_flag4(store, x) 690 } 691 fn roundtrip_flag8( 692 store: wasmtime::StoreContextMut<'_, Self::Data>, 693 x: Flag8, 694 ) -> impl ::core::future::Future< 695 Output = impl FnOnce( 696 wasmtime::StoreContextMut<'_, Self::Data>, 697 ) -> Flag8 + Send + Sync + 'static, 698 > + Send + Sync + 'static 699 where 700 Self: Sized, 701 { 702 <_T as Host>::roundtrip_flag8(store, x) 703 } 704 fn roundtrip_flag16( 705 store: wasmtime::StoreContextMut<'_, Self::Data>, 706 x: Flag16, 707 ) -> impl ::core::future::Future< 708 Output = impl FnOnce( 709 wasmtime::StoreContextMut<'_, Self::Data>, 710 ) -> Flag16 + Send + Sync + 'static, 711 > + Send + Sync + 'static 712 where 713 Self: Sized, 714 { 715 <_T as Host>::roundtrip_flag16(store, x) 716 } 717 fn roundtrip_flag32( 718 store: wasmtime::StoreContextMut<'_, Self::Data>, 719 x: Flag32, 720 ) -> impl ::core::future::Future< 721 Output = impl FnOnce( 722 wasmtime::StoreContextMut<'_, Self::Data>, 723 ) -> Flag32 + Send + Sync + 'static, 724 > + Send + Sync + 'static 725 where 726 Self: Sized, 727 { 728 <_T as Host>::roundtrip_flag32(store, x) 729 } 730 fn roundtrip_flag64( 731 store: wasmtime::StoreContextMut<'_, Self::Data>, 732 x: Flag64, 733 ) -> impl ::core::future::Future< 734 Output = impl FnOnce( 735 wasmtime::StoreContextMut<'_, Self::Data>, 736 ) -> Flag64 + Send + Sync + 'static, 737 > + Send + Sync + 'static 738 where 739 Self: Sized, 740 { 741 <_T as Host>::roundtrip_flag64(store, x) 742 } 743 } 744 } 745 } 746 } 747 pub mod exports { 748 pub mod foo { 749 pub mod foo { 750 #[allow(clippy::all)] 751 pub mod flegs { 752 #[allow(unused_imports)] 753 use wasmtime::component::__internal::{anyhow, Box}; 754 wasmtime::component::flags!( 755 Flag1 { #[component(name = "b0")] const B0; } 756 ); 757 const _: () = { 758 assert!( 759 1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32 760 ); 761 assert!( 762 1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32 763 ); 764 }; 765 wasmtime::component::flags!( 766 Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")] 767 const B1; } 768 ); 769 const _: () = { 770 assert!( 771 1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32 772 ); 773 assert!( 774 1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32 775 ); 776 }; 777 wasmtime::component::flags!( 778 Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")] 779 const B1; #[component(name = "b2")] const B2; #[component(name = 780 "b3")] const B3; } 781 ); 782 const _: () = { 783 assert!( 784 1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32 785 ); 786 assert!( 787 1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32 788 ); 789 }; 790 wasmtime::component::flags!( 791 Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")] 792 const B1; #[component(name = "b2")] const B2; #[component(name = 793 "b3")] const B3; #[component(name = "b4")] const B4; #[component(name 794 = "b5")] const B5; #[component(name = "b6")] const B6; 795 #[component(name = "b7")] const B7; } 796 ); 797 const _: () = { 798 assert!( 799 1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32 800 ); 801 assert!( 802 1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32 803 ); 804 }; 805 wasmtime::component::flags!( 806 Flag16 { #[component(name = "b0")] const B0; #[component(name = 807 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 808 = "b3")] const B3; #[component(name = "b4")] const B4; 809 #[component(name = "b5")] const B5; #[component(name = "b6")] const 810 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 811 const B8; #[component(name = "b9")] const B9; #[component(name = 812 "b10")] const B10; #[component(name = "b11")] const B11; 813 #[component(name = "b12")] const B12; #[component(name = "b13")] 814 const B13; #[component(name = "b14")] const B14; #[component(name = 815 "b15")] const B15; } 816 ); 817 const _: () = { 818 assert!( 819 2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32 820 ); 821 assert!( 822 2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32 823 ); 824 }; 825 wasmtime::component::flags!( 826 Flag32 { #[component(name = "b0")] const B0; #[component(name = 827 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 828 = "b3")] const B3; #[component(name = "b4")] const B4; 829 #[component(name = "b5")] const B5; #[component(name = "b6")] const 830 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 831 const B8; #[component(name = "b9")] const B9; #[component(name = 832 "b10")] const B10; #[component(name = "b11")] const B11; 833 #[component(name = "b12")] const B12; #[component(name = "b13")] 834 const B13; #[component(name = "b14")] const B14; #[component(name = 835 "b15")] const B15; #[component(name = "b16")] const B16; 836 #[component(name = "b17")] const B17; #[component(name = "b18")] 837 const B18; #[component(name = "b19")] const B19; #[component(name = 838 "b20")] const B20; #[component(name = "b21")] const B21; 839 #[component(name = "b22")] const B22; #[component(name = "b23")] 840 const B23; #[component(name = "b24")] const B24; #[component(name = 841 "b25")] const B25; #[component(name = "b26")] const B26; 842 #[component(name = "b27")] const B27; #[component(name = "b28")] 843 const B28; #[component(name = "b29")] const B29; #[component(name = 844 "b30")] const B30; #[component(name = "b31")] const B31; } 845 ); 846 const _: () = { 847 assert!( 848 4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32 849 ); 850 assert!( 851 4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32 852 ); 853 }; 854 wasmtime::component::flags!( 855 Flag64 { #[component(name = "b0")] const B0; #[component(name = 856 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 857 = "b3")] const B3; #[component(name = "b4")] const B4; 858 #[component(name = "b5")] const B5; #[component(name = "b6")] const 859 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 860 const B8; #[component(name = "b9")] const B9; #[component(name = 861 "b10")] const B10; #[component(name = "b11")] const B11; 862 #[component(name = "b12")] const B12; #[component(name = "b13")] 863 const B13; #[component(name = "b14")] const B14; #[component(name = 864 "b15")] const B15; #[component(name = "b16")] const B16; 865 #[component(name = "b17")] const B17; #[component(name = "b18")] 866 const B18; #[component(name = "b19")] const B19; #[component(name = 867 "b20")] const B20; #[component(name = "b21")] const B21; 868 #[component(name = "b22")] const B22; #[component(name = "b23")] 869 const B23; #[component(name = "b24")] const B24; #[component(name = 870 "b25")] const B25; #[component(name = "b26")] const B26; 871 #[component(name = "b27")] const B27; #[component(name = "b28")] 872 const B28; #[component(name = "b29")] const B29; #[component(name = 873 "b30")] const B30; #[component(name = "b31")] const B31; 874 #[component(name = "b32")] const B32; #[component(name = "b33")] 875 const B33; #[component(name = "b34")] const B34; #[component(name = 876 "b35")] const B35; #[component(name = "b36")] const B36; 877 #[component(name = "b37")] const B37; #[component(name = "b38")] 878 const B38; #[component(name = "b39")] const B39; #[component(name = 879 "b40")] const B40; #[component(name = "b41")] const B41; 880 #[component(name = "b42")] const B42; #[component(name = "b43")] 881 const B43; #[component(name = "b44")] const B44; #[component(name = 882 "b45")] const B45; #[component(name = "b46")] const B46; 883 #[component(name = "b47")] const B47; #[component(name = "b48")] 884 const B48; #[component(name = "b49")] const B49; #[component(name = 885 "b50")] const B50; #[component(name = "b51")] const B51; 886 #[component(name = "b52")] const B52; #[component(name = "b53")] 887 const B53; #[component(name = "b54")] const B54; #[component(name = 888 "b55")] const B55; #[component(name = "b56")] const B56; 889 #[component(name = "b57")] const B57; #[component(name = "b58")] 890 const B58; #[component(name = "b59")] const B59; #[component(name = 891 "b60")] const B60; #[component(name = "b61")] const B61; 892 #[component(name = "b62")] const B62; #[component(name = "b63")] 893 const B63; } 894 ); 895 const _: () = { 896 assert!( 897 8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32 898 ); 899 assert!( 900 4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32 901 ); 902 }; 903 pub struct Guest { 904 roundtrip_flag1: wasmtime::component::Func, 905 roundtrip_flag2: wasmtime::component::Func, 906 roundtrip_flag4: wasmtime::component::Func, 907 roundtrip_flag8: wasmtime::component::Func, 908 roundtrip_flag16: wasmtime::component::Func, 909 roundtrip_flag32: wasmtime::component::Func, 910 roundtrip_flag64: wasmtime::component::Func, 911 } 912 #[derive(Clone)] 913 pub struct GuestIndices { 914 roundtrip_flag1: wasmtime::component::ComponentExportIndex, 915 roundtrip_flag2: wasmtime::component::ComponentExportIndex, 916 roundtrip_flag4: wasmtime::component::ComponentExportIndex, 917 roundtrip_flag8: wasmtime::component::ComponentExportIndex, 918 roundtrip_flag16: wasmtime::component::ComponentExportIndex, 919 roundtrip_flag32: wasmtime::component::ComponentExportIndex, 920 roundtrip_flag64: wasmtime::component::ComponentExportIndex, 921 } 922 impl GuestIndices { 923 /// Constructor for [`GuestIndices`] which takes a 924 /// [`Component`](wasmtime::component::Component) as input and can be executed 925 /// before instantiation. 926 /// 927 /// This constructor can be used to front-load string lookups to find exports 928 /// within a component. 929 pub fn new( 930 component: &wasmtime::component::Component, 931 ) -> wasmtime::Result<GuestIndices> { 932 let (_, instance) = component 933 .export_index(None, "foo:foo/flegs") 934 .ok_or_else(|| { 935 anyhow::anyhow!( 936 "no exported instance named `foo:foo/flegs`" 937 ) 938 })?; 939 Self::_new(|name| { 940 component.export_index(Some(&instance), name).map(|p| p.1) 941 }) 942 } 943 /// This constructor is similar to [`GuestIndices::new`] except that it 944 /// performs string lookups after instantiation time. 945 pub fn new_instance( 946 mut store: impl wasmtime::AsContextMut, 947 instance: &wasmtime::component::Instance, 948 ) -> wasmtime::Result<GuestIndices> { 949 let instance_export = instance 950 .get_export(&mut store, None, "foo:foo/flegs") 951 .ok_or_else(|| { 952 anyhow::anyhow!( 953 "no exported instance named `foo:foo/flegs`" 954 ) 955 })?; 956 Self::_new(|name| { 957 instance.get_export(&mut store, Some(&instance_export), name) 958 }) 959 } 960 fn _new( 961 mut lookup: impl FnMut( 962 &str, 963 ) -> Option<wasmtime::component::ComponentExportIndex>, 964 ) -> wasmtime::Result<GuestIndices> { 965 let mut lookup = move |name| { 966 lookup(name) 967 .ok_or_else(|| { 968 anyhow::anyhow!( 969 "instance export `foo:foo/flegs` does \ 970 not have export `{name}`" 971 ) 972 }) 973 }; 974 let _ = &mut lookup; 975 let roundtrip_flag1 = lookup("roundtrip-flag1")?; 976 let roundtrip_flag2 = lookup("roundtrip-flag2")?; 977 let roundtrip_flag4 = lookup("roundtrip-flag4")?; 978 let roundtrip_flag8 = lookup("roundtrip-flag8")?; 979 let roundtrip_flag16 = lookup("roundtrip-flag16")?; 980 let roundtrip_flag32 = lookup("roundtrip-flag32")?; 981 let roundtrip_flag64 = lookup("roundtrip-flag64")?; 982 Ok(GuestIndices { 983 roundtrip_flag1, 984 roundtrip_flag2, 985 roundtrip_flag4, 986 roundtrip_flag8, 987 roundtrip_flag16, 988 roundtrip_flag32, 989 roundtrip_flag64, 990 }) 991 } 992 pub fn load( 993 &self, 994 mut store: impl wasmtime::AsContextMut, 995 instance: &wasmtime::component::Instance, 996 ) -> wasmtime::Result<Guest> { 997 let mut store = store.as_context_mut(); 998 let _ = &mut store; 999 let _instance = instance; 1000 let roundtrip_flag1 = *_instance 1001 .get_typed_func::< 1002 (Flag1,), 1003 (Flag1,), 1004 >(&mut store, &self.roundtrip_flag1)? 1005 .func(); 1006 let roundtrip_flag2 = *_instance 1007 .get_typed_func::< 1008 (Flag2,), 1009 (Flag2,), 1010 >(&mut store, &self.roundtrip_flag2)? 1011 .func(); 1012 let roundtrip_flag4 = *_instance 1013 .get_typed_func::< 1014 (Flag4,), 1015 (Flag4,), 1016 >(&mut store, &self.roundtrip_flag4)? 1017 .func(); 1018 let roundtrip_flag8 = *_instance 1019 .get_typed_func::< 1020 (Flag8,), 1021 (Flag8,), 1022 >(&mut store, &self.roundtrip_flag8)? 1023 .func(); 1024 let roundtrip_flag16 = *_instance 1025 .get_typed_func::< 1026 (Flag16,), 1027 (Flag16,), 1028 >(&mut store, &self.roundtrip_flag16)? 1029 .func(); 1030 let roundtrip_flag32 = *_instance 1031 .get_typed_func::< 1032 (Flag32,), 1033 (Flag32,), 1034 >(&mut store, &self.roundtrip_flag32)? 1035 .func(); 1036 let roundtrip_flag64 = *_instance 1037 .get_typed_func::< 1038 (Flag64,), 1039 (Flag64,), 1040 >(&mut store, &self.roundtrip_flag64)? 1041 .func(); 1042 Ok(Guest { 1043 roundtrip_flag1, 1044 roundtrip_flag2, 1045 roundtrip_flag4, 1046 roundtrip_flag8, 1047 roundtrip_flag16, 1048 roundtrip_flag32, 1049 roundtrip_flag64, 1050 }) 1051 } 1052 } 1053 impl Guest { 1054 pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>( 1055 &self, 1056 mut store: S, 1057 arg0: Flag1, 1058 ) -> wasmtime::Result<wasmtime::component::Promise<Flag1>> 1059 where 1060 <S as wasmtime::AsContext>::Data: Send + 'static, 1061 { 1062 let callee = unsafe { 1063 wasmtime::component::TypedFunc::< 1064 (Flag1,), 1065 (Flag1,), 1066 >::new_unchecked(self.roundtrip_flag1) 1067 }; 1068 let promise = callee 1069 .call_concurrent(store.as_context_mut(), (arg0,)) 1070 .await?; 1071 Ok(promise.map(|(v,)| v)) 1072 } 1073 pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>( 1074 &self, 1075 mut store: S, 1076 arg0: Flag2, 1077 ) -> wasmtime::Result<wasmtime::component::Promise<Flag2>> 1078 where 1079 <S as wasmtime::AsContext>::Data: Send + 'static, 1080 { 1081 let callee = unsafe { 1082 wasmtime::component::TypedFunc::< 1083 (Flag2,), 1084 (Flag2,), 1085 >::new_unchecked(self.roundtrip_flag2) 1086 }; 1087 let promise = callee 1088 .call_concurrent(store.as_context_mut(), (arg0,)) 1089 .await?; 1090 Ok(promise.map(|(v,)| v)) 1091 } 1092 pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>( 1093 &self, 1094 mut store: S, 1095 arg0: Flag4, 1096 ) -> wasmtime::Result<wasmtime::component::Promise<Flag4>> 1097 where 1098 <S as wasmtime::AsContext>::Data: Send + 'static, 1099 { 1100 let callee = unsafe { 1101 wasmtime::component::TypedFunc::< 1102 (Flag4,), 1103 (Flag4,), 1104 >::new_unchecked(self.roundtrip_flag4) 1105 }; 1106 let promise = callee 1107 .call_concurrent(store.as_context_mut(), (arg0,)) 1108 .await?; 1109 Ok(promise.map(|(v,)| v)) 1110 } 1111 pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>( 1112 &self, 1113 mut store: S, 1114 arg0: Flag8, 1115 ) -> wasmtime::Result<wasmtime::component::Promise<Flag8>> 1116 where 1117 <S as wasmtime::AsContext>::Data: Send + 'static, 1118 { 1119 let callee = unsafe { 1120 wasmtime::component::TypedFunc::< 1121 (Flag8,), 1122 (Flag8,), 1123 >::new_unchecked(self.roundtrip_flag8) 1124 }; 1125 let promise = callee 1126 .call_concurrent(store.as_context_mut(), (arg0,)) 1127 .await?; 1128 Ok(promise.map(|(v,)| v)) 1129 } 1130 pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>( 1131 &self, 1132 mut store: S, 1133 arg0: Flag16, 1134 ) -> wasmtime::Result<wasmtime::component::Promise<Flag16>> 1135 where 1136 <S as wasmtime::AsContext>::Data: Send + 'static, 1137 { 1138 let callee = unsafe { 1139 wasmtime::component::TypedFunc::< 1140 (Flag16,), 1141 (Flag16,), 1142 >::new_unchecked(self.roundtrip_flag16) 1143 }; 1144 let promise = callee 1145 .call_concurrent(store.as_context_mut(), (arg0,)) 1146 .await?; 1147 Ok(promise.map(|(v,)| v)) 1148 } 1149 pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>( 1150 &self, 1151 mut store: S, 1152 arg0: Flag32, 1153 ) -> wasmtime::Result<wasmtime::component::Promise<Flag32>> 1154 where 1155 <S as wasmtime::AsContext>::Data: Send + 'static, 1156 { 1157 let callee = unsafe { 1158 wasmtime::component::TypedFunc::< 1159 (Flag32,), 1160 (Flag32,), 1161 >::new_unchecked(self.roundtrip_flag32) 1162 }; 1163 let promise = callee 1164 .call_concurrent(store.as_context_mut(), (arg0,)) 1165 .await?; 1166 Ok(promise.map(|(v,)| v)) 1167 } 1168 pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>( 1169 &self, 1170 mut store: S, 1171 arg0: Flag64, 1172 ) -> wasmtime::Result<wasmtime::component::Promise<Flag64>> 1173 where 1174 <S as wasmtime::AsContext>::Data: Send + 'static, 1175 { 1176 let callee = unsafe { 1177 wasmtime::component::TypedFunc::< 1178 (Flag64,), 1179 (Flag64,), 1180 >::new_unchecked(self.roundtrip_flag64) 1181 }; 1182 let promise = callee 1183 .call_concurrent(store.as_context_mut(), (arg0,)) 1184 .await?; 1185 Ok(promise.map(|(v,)| v)) 1186 } 1187 } 1188 } 1189 } 1190 } 1191 } 1192