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: 'static> { 10 instance_pre: wasmtime::component::InstancePre<T>, 11 indices: TheFlagsIndices, 12 } 13 impl<T: 'static> 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: 'static> 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)?; 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, 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 /// These methods are all equivalent to one another and move 89 /// around the tradeoff of what work is performed when. 90 /// 91 /// [`Store`]: wasmtime::Store 92 /// [`Component`]: wasmtime::component::Component 93 /// [`Linker`]: wasmtime::component::Linker 94 pub struct TheFlags { 95 interface0: exports::foo::foo::flegs::Guest, 96 } 97 const _: () = { 98 #[allow(unused_imports)] 99 use wasmtime::component::__internal::anyhow; 100 impl TheFlagsIndices { 101 /// Creates a new copy of `TheFlagsIndices` bindings which can then 102 /// be used to instantiate into a particular store. 103 /// 104 /// This method may fail if the component does not have the 105 /// required exports. 106 pub fn new<_T>( 107 _instance_pre: &wasmtime::component::InstancePre<_T>, 108 ) -> wasmtime::Result<Self> { 109 let _component = _instance_pre.component(); 110 let _instance_type = _instance_pre.instance_type(); 111 let interface0 = exports::foo::foo::flegs::GuestIndices::new(_instance_pre)?; 112 Ok(TheFlagsIndices { interface0 }) 113 } 114 /// Uses the indices stored in `self` to load an instance 115 /// of [`TheFlags`] from the instance provided. 116 /// 117 /// Note that at this time this method will additionally 118 /// perform type-checks of all exports. 119 pub fn load( 120 &self, 121 mut store: impl wasmtime::AsContextMut, 122 instance: &wasmtime::component::Instance, 123 ) -> wasmtime::Result<TheFlags> { 124 let _ = &mut store; 125 let _instance = instance; 126 let interface0 = self.interface0.load(&mut store, &_instance)?; 127 Ok(TheFlags { interface0 }) 128 } 129 } 130 impl TheFlags { 131 /// Convenience wrapper around [`TheFlagsPre::new`] and 132 /// [`TheFlagsPre::instantiate_async`]. 133 pub async fn instantiate_async<_T>( 134 store: impl wasmtime::AsContextMut<Data = _T>, 135 component: &wasmtime::component::Component, 136 linker: &wasmtime::component::Linker<_T>, 137 ) -> wasmtime::Result<TheFlags> 138 where 139 _T: Send, 140 { 141 let pre = linker.instantiate_pre(component)?; 142 TheFlagsPre::new(pre)?.instantiate_async(store).await 143 } 144 /// Convenience wrapper around [`TheFlagsIndices::new`] and 145 /// [`TheFlagsIndices::load`]. 146 pub fn new( 147 mut store: impl wasmtime::AsContextMut, 148 instance: &wasmtime::component::Instance, 149 ) -> wasmtime::Result<TheFlags> { 150 let indices = TheFlagsIndices::new(&instance.instance_pre(&store))?; 151 indices.load(&mut store, instance) 152 } 153 pub fn add_to_linker<T, D>( 154 linker: &mut wasmtime::component::Linker<T>, 155 host_getter: fn(&mut T) -> D::Data<'_>, 156 ) -> wasmtime::Result<()> 157 where 158 D: wasmtime::component::HasData, 159 for<'a> D::Data<'a>: foo::foo::flegs::Host + Send, 160 T: 'static + Send, 161 { 162 foo::foo::flegs::add_to_linker::<T, D>(linker, host_getter)?; 163 Ok(()) 164 } 165 pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest { 166 &self.interface0 167 } 168 } 169 }; 170 pub mod foo { 171 pub mod foo { 172 #[allow(clippy::all)] 173 pub mod flegs { 174 #[allow(unused_imports)] 175 use wasmtime::component::__internal::{anyhow, Box}; 176 wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; }); 177 const _: () = { 178 assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32); 179 assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32); 180 }; 181 wasmtime::component::flags!( 182 Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")] 183 const B1; } 184 ); 185 const _: () = { 186 assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32); 187 assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32); 188 }; 189 wasmtime::component::flags!( 190 Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")] 191 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 192 const B3; } 193 ); 194 const _: () = { 195 assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32); 196 assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32); 197 }; 198 wasmtime::component::flags!( 199 Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")] 200 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 201 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 202 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 203 const B7; } 204 ); 205 const _: () = { 206 assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32); 207 assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32); 208 }; 209 wasmtime::component::flags!( 210 Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")] 211 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 212 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 213 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 214 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 215 const B9; #[component(name = "b10")] const B10; #[component(name = 216 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 217 = "b13")] const B13; #[component(name = "b14")] const B14; 218 #[component(name = "b15")] const B15; } 219 ); 220 const _: () = { 221 assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32); 222 assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32); 223 }; 224 wasmtime::component::flags!( 225 Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")] 226 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 227 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 228 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 229 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 230 const B9; #[component(name = "b10")] const B10; #[component(name = 231 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 232 = "b13")] const B13; #[component(name = "b14")] const B14; 233 #[component(name = "b15")] const B15; #[component(name = "b16")] const 234 B16; #[component(name = "b17")] const B17; #[component(name = "b18")] 235 const B18; #[component(name = "b19")] const B19; #[component(name = 236 "b20")] const B20; #[component(name = "b21")] const B21; #[component(name 237 = "b22")] const B22; #[component(name = "b23")] const B23; 238 #[component(name = "b24")] const B24; #[component(name = "b25")] const 239 B25; #[component(name = "b26")] const B26; #[component(name = "b27")] 240 const B27; #[component(name = "b28")] const B28; #[component(name = 241 "b29")] const B29; #[component(name = "b30")] const B30; #[component(name 242 = "b31")] const B31; } 243 ); 244 const _: () = { 245 assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32); 246 assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32); 247 }; 248 wasmtime::component::flags!( 249 Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")] 250 const B1; #[component(name = "b2")] const B2; #[component(name = "b3")] 251 const B3; #[component(name = "b4")] const B4; #[component(name = "b5")] 252 const B5; #[component(name = "b6")] const B6; #[component(name = "b7")] 253 const B7; #[component(name = "b8")] const B8; #[component(name = "b9")] 254 const B9; #[component(name = "b10")] const B10; #[component(name = 255 "b11")] const B11; #[component(name = "b12")] const B12; #[component(name 256 = "b13")] const B13; #[component(name = "b14")] const B14; 257 #[component(name = "b15")] const B15; #[component(name = "b16")] const 258 B16; #[component(name = "b17")] const B17; #[component(name = "b18")] 259 const B18; #[component(name = "b19")] const B19; #[component(name = 260 "b20")] const B20; #[component(name = "b21")] const B21; #[component(name 261 = "b22")] const B22; #[component(name = "b23")] const B23; 262 #[component(name = "b24")] const B24; #[component(name = "b25")] const 263 B25; #[component(name = "b26")] const B26; #[component(name = "b27")] 264 const B27; #[component(name = "b28")] const B28; #[component(name = 265 "b29")] const B29; #[component(name = "b30")] const B30; #[component(name 266 = "b31")] const B31; #[component(name = "b32")] const B32; 267 #[component(name = "b33")] const B33; #[component(name = "b34")] const 268 B34; #[component(name = "b35")] const B35; #[component(name = "b36")] 269 const B36; #[component(name = "b37")] const B37; #[component(name = 270 "b38")] const B38; #[component(name = "b39")] const B39; #[component(name 271 = "b40")] const B40; #[component(name = "b41")] const B41; 272 #[component(name = "b42")] const B42; #[component(name = "b43")] const 273 B43; #[component(name = "b44")] const B44; #[component(name = "b45")] 274 const B45; #[component(name = "b46")] const B46; #[component(name = 275 "b47")] const B47; #[component(name = "b48")] const B48; #[component(name 276 = "b49")] const B49; #[component(name = "b50")] const B50; 277 #[component(name = "b51")] const B51; #[component(name = "b52")] const 278 B52; #[component(name = "b53")] const B53; #[component(name = "b54")] 279 const B54; #[component(name = "b55")] const B55; #[component(name = 280 "b56")] const B56; #[component(name = "b57")] const B57; #[component(name 281 = "b58")] const B58; #[component(name = "b59")] const B59; 282 #[component(name = "b60")] const B60; #[component(name = "b61")] const 283 B61; #[component(name = "b62")] const B62; #[component(name = "b63")] 284 const B63; } 285 ); 286 const _: () = { 287 assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32); 288 assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32); 289 }; 290 #[wasmtime::component::__internal::trait_variant_make(::core::marker::Send)] 291 pub trait Host: Send { 292 async fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1; 293 async fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2; 294 async fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4; 295 async fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8; 296 async fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16; 297 async fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32; 298 async fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64; 299 } 300 impl<_T: Host + ?Sized + Send> Host for &mut _T { 301 async fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1 { 302 Host::roundtrip_flag1(*self, x).await 303 } 304 async fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2 { 305 Host::roundtrip_flag2(*self, x).await 306 } 307 async fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4 { 308 Host::roundtrip_flag4(*self, x).await 309 } 310 async fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8 { 311 Host::roundtrip_flag8(*self, x).await 312 } 313 async fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16 { 314 Host::roundtrip_flag16(*self, x).await 315 } 316 async fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32 { 317 Host::roundtrip_flag32(*self, x).await 318 } 319 async fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64 { 320 Host::roundtrip_flag64(*self, x).await 321 } 322 } 323 pub fn add_to_linker<T, D>( 324 linker: &mut wasmtime::component::Linker<T>, 325 host_getter: fn(&mut T) -> D::Data<'_>, 326 ) -> wasmtime::Result<()> 327 where 328 D: wasmtime::component::HasData, 329 for<'a> D::Data<'a>: Host, 330 T: 'static + Send, 331 { 332 let mut inst = linker.instance("foo:foo/flegs")?; 333 inst.func_wrap_async( 334 "roundtrip-flag1", 335 move | 336 mut caller: wasmtime::StoreContextMut<'_, T>, 337 (arg0,): (Flag1,)| 338 { 339 wasmtime::component::__internal::Box::new(async move { 340 let host = &mut host_getter(caller.data_mut()); 341 let r = Host::roundtrip_flag1(host, arg0).await; 342 Ok((r,)) 343 }) 344 }, 345 )?; 346 inst.func_wrap_async( 347 "roundtrip-flag2", 348 move | 349 mut caller: wasmtime::StoreContextMut<'_, T>, 350 (arg0,): (Flag2,)| 351 { 352 wasmtime::component::__internal::Box::new(async move { 353 let host = &mut host_getter(caller.data_mut()); 354 let r = Host::roundtrip_flag2(host, arg0).await; 355 Ok((r,)) 356 }) 357 }, 358 )?; 359 inst.func_wrap_async( 360 "roundtrip-flag4", 361 move | 362 mut caller: wasmtime::StoreContextMut<'_, T>, 363 (arg0,): (Flag4,)| 364 { 365 wasmtime::component::__internal::Box::new(async move { 366 let host = &mut host_getter(caller.data_mut()); 367 let r = Host::roundtrip_flag4(host, arg0).await; 368 Ok((r,)) 369 }) 370 }, 371 )?; 372 inst.func_wrap_async( 373 "roundtrip-flag8", 374 move | 375 mut caller: wasmtime::StoreContextMut<'_, T>, 376 (arg0,): (Flag8,)| 377 { 378 wasmtime::component::__internal::Box::new(async move { 379 let host = &mut host_getter(caller.data_mut()); 380 let r = Host::roundtrip_flag8(host, arg0).await; 381 Ok((r,)) 382 }) 383 }, 384 )?; 385 inst.func_wrap_async( 386 "roundtrip-flag16", 387 move | 388 mut caller: wasmtime::StoreContextMut<'_, T>, 389 (arg0,): (Flag16,)| 390 { 391 wasmtime::component::__internal::Box::new(async move { 392 let host = &mut host_getter(caller.data_mut()); 393 let r = Host::roundtrip_flag16(host, arg0).await; 394 Ok((r,)) 395 }) 396 }, 397 )?; 398 inst.func_wrap_async( 399 "roundtrip-flag32", 400 move | 401 mut caller: wasmtime::StoreContextMut<'_, T>, 402 (arg0,): (Flag32,)| 403 { 404 wasmtime::component::__internal::Box::new(async move { 405 let host = &mut host_getter(caller.data_mut()); 406 let r = Host::roundtrip_flag32(host, arg0).await; 407 Ok((r,)) 408 }) 409 }, 410 )?; 411 inst.func_wrap_async( 412 "roundtrip-flag64", 413 move | 414 mut caller: wasmtime::StoreContextMut<'_, T>, 415 (arg0,): (Flag64,)| 416 { 417 wasmtime::component::__internal::Box::new(async move { 418 let host = &mut host_getter(caller.data_mut()); 419 let r = Host::roundtrip_flag64(host, arg0).await; 420 Ok((r,)) 421 }) 422 }, 423 )?; 424 Ok(()) 425 } 426 } 427 } 428 } 429 pub mod exports { 430 pub mod foo { 431 pub mod foo { 432 #[allow(clippy::all)] 433 pub mod flegs { 434 #[allow(unused_imports)] 435 use wasmtime::component::__internal::{anyhow, Box}; 436 wasmtime::component::flags!( 437 Flag1 { #[component(name = "b0")] const B0; } 438 ); 439 const _: () = { 440 assert!( 441 1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32 442 ); 443 assert!( 444 1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32 445 ); 446 }; 447 wasmtime::component::flags!( 448 Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")] 449 const B1; } 450 ); 451 const _: () = { 452 assert!( 453 1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32 454 ); 455 assert!( 456 1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32 457 ); 458 }; 459 wasmtime::component::flags!( 460 Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")] 461 const B1; #[component(name = "b2")] const B2; #[component(name = 462 "b3")] const B3; } 463 ); 464 const _: () = { 465 assert!( 466 1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32 467 ); 468 assert!( 469 1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32 470 ); 471 }; 472 wasmtime::component::flags!( 473 Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")] 474 const B1; #[component(name = "b2")] const B2; #[component(name = 475 "b3")] const B3; #[component(name = "b4")] const B4; #[component(name 476 = "b5")] const B5; #[component(name = "b6")] const B6; 477 #[component(name = "b7")] const B7; } 478 ); 479 const _: () = { 480 assert!( 481 1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32 482 ); 483 assert!( 484 1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32 485 ); 486 }; 487 wasmtime::component::flags!( 488 Flag16 { #[component(name = "b0")] const B0; #[component(name = 489 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 490 = "b3")] const B3; #[component(name = "b4")] const B4; 491 #[component(name = "b5")] const B5; #[component(name = "b6")] const 492 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 493 const B8; #[component(name = "b9")] const B9; #[component(name = 494 "b10")] const B10; #[component(name = "b11")] const B11; 495 #[component(name = "b12")] const B12; #[component(name = "b13")] 496 const B13; #[component(name = "b14")] const B14; #[component(name = 497 "b15")] const B15; } 498 ); 499 const _: () = { 500 assert!( 501 2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32 502 ); 503 assert!( 504 2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32 505 ); 506 }; 507 wasmtime::component::flags!( 508 Flag32 { #[component(name = "b0")] const B0; #[component(name = 509 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 510 = "b3")] const B3; #[component(name = "b4")] const B4; 511 #[component(name = "b5")] const B5; #[component(name = "b6")] const 512 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 513 const B8; #[component(name = "b9")] const B9; #[component(name = 514 "b10")] const B10; #[component(name = "b11")] const B11; 515 #[component(name = "b12")] const B12; #[component(name = "b13")] 516 const B13; #[component(name = "b14")] const B14; #[component(name = 517 "b15")] const B15; #[component(name = "b16")] const B16; 518 #[component(name = "b17")] const B17; #[component(name = "b18")] 519 const B18; #[component(name = "b19")] const B19; #[component(name = 520 "b20")] const B20; #[component(name = "b21")] const B21; 521 #[component(name = "b22")] const B22; #[component(name = "b23")] 522 const B23; #[component(name = "b24")] const B24; #[component(name = 523 "b25")] const B25; #[component(name = "b26")] const B26; 524 #[component(name = "b27")] const B27; #[component(name = "b28")] 525 const B28; #[component(name = "b29")] const B29; #[component(name = 526 "b30")] const B30; #[component(name = "b31")] const B31; } 527 ); 528 const _: () = { 529 assert!( 530 4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32 531 ); 532 assert!( 533 4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32 534 ); 535 }; 536 wasmtime::component::flags!( 537 Flag64 { #[component(name = "b0")] const B0; #[component(name = 538 "b1")] const B1; #[component(name = "b2")] const B2; #[component(name 539 = "b3")] const B3; #[component(name = "b4")] const B4; 540 #[component(name = "b5")] const B5; #[component(name = "b6")] const 541 B6; #[component(name = "b7")] const B7; #[component(name = "b8")] 542 const B8; #[component(name = "b9")] const B9; #[component(name = 543 "b10")] const B10; #[component(name = "b11")] const B11; 544 #[component(name = "b12")] const B12; #[component(name = "b13")] 545 const B13; #[component(name = "b14")] const B14; #[component(name = 546 "b15")] const B15; #[component(name = "b16")] const B16; 547 #[component(name = "b17")] const B17; #[component(name = "b18")] 548 const B18; #[component(name = "b19")] const B19; #[component(name = 549 "b20")] const B20; #[component(name = "b21")] const B21; 550 #[component(name = "b22")] const B22; #[component(name = "b23")] 551 const B23; #[component(name = "b24")] const B24; #[component(name = 552 "b25")] const B25; #[component(name = "b26")] const B26; 553 #[component(name = "b27")] const B27; #[component(name = "b28")] 554 const B28; #[component(name = "b29")] const B29; #[component(name = 555 "b30")] const B30; #[component(name = "b31")] const B31; 556 #[component(name = "b32")] const B32; #[component(name = "b33")] 557 const B33; #[component(name = "b34")] const B34; #[component(name = 558 "b35")] const B35; #[component(name = "b36")] const B36; 559 #[component(name = "b37")] const B37; #[component(name = "b38")] 560 const B38; #[component(name = "b39")] const B39; #[component(name = 561 "b40")] const B40; #[component(name = "b41")] const B41; 562 #[component(name = "b42")] const B42; #[component(name = "b43")] 563 const B43; #[component(name = "b44")] const B44; #[component(name = 564 "b45")] const B45; #[component(name = "b46")] const B46; 565 #[component(name = "b47")] const B47; #[component(name = "b48")] 566 const B48; #[component(name = "b49")] const B49; #[component(name = 567 "b50")] const B50; #[component(name = "b51")] const B51; 568 #[component(name = "b52")] const B52; #[component(name = "b53")] 569 const B53; #[component(name = "b54")] const B54; #[component(name = 570 "b55")] const B55; #[component(name = "b56")] const B56; 571 #[component(name = "b57")] const B57; #[component(name = "b58")] 572 const B58; #[component(name = "b59")] const B59; #[component(name = 573 "b60")] const B60; #[component(name = "b61")] const B61; 574 #[component(name = "b62")] const B62; #[component(name = "b63")] 575 const B63; } 576 ); 577 const _: () = { 578 assert!( 579 8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32 580 ); 581 assert!( 582 4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32 583 ); 584 }; 585 pub struct Guest { 586 roundtrip_flag1: wasmtime::component::Func, 587 roundtrip_flag2: wasmtime::component::Func, 588 roundtrip_flag4: wasmtime::component::Func, 589 roundtrip_flag8: wasmtime::component::Func, 590 roundtrip_flag16: wasmtime::component::Func, 591 roundtrip_flag32: wasmtime::component::Func, 592 roundtrip_flag64: wasmtime::component::Func, 593 } 594 #[derive(Clone)] 595 pub struct GuestIndices { 596 roundtrip_flag1: wasmtime::component::ComponentExportIndex, 597 roundtrip_flag2: wasmtime::component::ComponentExportIndex, 598 roundtrip_flag4: wasmtime::component::ComponentExportIndex, 599 roundtrip_flag8: wasmtime::component::ComponentExportIndex, 600 roundtrip_flag16: wasmtime::component::ComponentExportIndex, 601 roundtrip_flag32: wasmtime::component::ComponentExportIndex, 602 roundtrip_flag64: wasmtime::component::ComponentExportIndex, 603 } 604 impl GuestIndices { 605 /// Constructor for [`GuestIndices`] which takes a 606 /// [`Component`](wasmtime::component::Component) as input and can be executed 607 /// before instantiation. 608 /// 609 /// This constructor can be used to front-load string lookups to find exports 610 /// within a component. 611 pub fn new<_T>( 612 _instance_pre: &wasmtime::component::InstancePre<_T>, 613 ) -> wasmtime::Result<GuestIndices> { 614 let instance = _instance_pre 615 .component() 616 .get_export_index(None, "foo:foo/flegs") 617 .ok_or_else(|| { 618 anyhow::anyhow!( 619 "no exported instance named `foo:foo/flegs`" 620 ) 621 })?; 622 let mut lookup = move |name| { 623 _instance_pre 624 .component() 625 .get_export_index(Some(&instance), name) 626 .ok_or_else(|| { 627 anyhow::anyhow!( 628 "instance export `foo:foo/flegs` does \ 629 not have export `{name}`" 630 ) 631 }) 632 }; 633 let _ = &mut lookup; 634 let roundtrip_flag1 = lookup("roundtrip-flag1")?; 635 let roundtrip_flag2 = lookup("roundtrip-flag2")?; 636 let roundtrip_flag4 = lookup("roundtrip-flag4")?; 637 let roundtrip_flag8 = lookup("roundtrip-flag8")?; 638 let roundtrip_flag16 = lookup("roundtrip-flag16")?; 639 let roundtrip_flag32 = lookup("roundtrip-flag32")?; 640 let roundtrip_flag64 = lookup("roundtrip-flag64")?; 641 Ok(GuestIndices { 642 roundtrip_flag1, 643 roundtrip_flag2, 644 roundtrip_flag4, 645 roundtrip_flag8, 646 roundtrip_flag16, 647 roundtrip_flag32, 648 roundtrip_flag64, 649 }) 650 } 651 pub fn load( 652 &self, 653 mut store: impl wasmtime::AsContextMut, 654 instance: &wasmtime::component::Instance, 655 ) -> wasmtime::Result<Guest> { 656 let _instance = instance; 657 let _instance_pre = _instance.instance_pre(&store); 658 let _instance_type = _instance_pre.instance_type(); 659 let mut store = store.as_context_mut(); 660 let _ = &mut store; 661 let roundtrip_flag1 = *_instance 662 .get_typed_func::< 663 (Flag1,), 664 (Flag1,), 665 >(&mut store, &self.roundtrip_flag1)? 666 .func(); 667 let roundtrip_flag2 = *_instance 668 .get_typed_func::< 669 (Flag2,), 670 (Flag2,), 671 >(&mut store, &self.roundtrip_flag2)? 672 .func(); 673 let roundtrip_flag4 = *_instance 674 .get_typed_func::< 675 (Flag4,), 676 (Flag4,), 677 >(&mut store, &self.roundtrip_flag4)? 678 .func(); 679 let roundtrip_flag8 = *_instance 680 .get_typed_func::< 681 (Flag8,), 682 (Flag8,), 683 >(&mut store, &self.roundtrip_flag8)? 684 .func(); 685 let roundtrip_flag16 = *_instance 686 .get_typed_func::< 687 (Flag16,), 688 (Flag16,), 689 >(&mut store, &self.roundtrip_flag16)? 690 .func(); 691 let roundtrip_flag32 = *_instance 692 .get_typed_func::< 693 (Flag32,), 694 (Flag32,), 695 >(&mut store, &self.roundtrip_flag32)? 696 .func(); 697 let roundtrip_flag64 = *_instance 698 .get_typed_func::< 699 (Flag64,), 700 (Flag64,), 701 >(&mut store, &self.roundtrip_flag64)? 702 .func(); 703 Ok(Guest { 704 roundtrip_flag1, 705 roundtrip_flag2, 706 roundtrip_flag4, 707 roundtrip_flag8, 708 roundtrip_flag16, 709 roundtrip_flag32, 710 roundtrip_flag64, 711 }) 712 } 713 } 714 impl Guest { 715 pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>( 716 &self, 717 mut store: S, 718 arg0: Flag1, 719 ) -> wasmtime::Result<Flag1> 720 where 721 <S as wasmtime::AsContext>::Data: Send, 722 { 723 let callee = unsafe { 724 wasmtime::component::TypedFunc::< 725 (Flag1,), 726 (Flag1,), 727 >::new_unchecked(self.roundtrip_flag1) 728 }; 729 let (ret0,) = callee 730 .call_async(store.as_context_mut(), (arg0,)) 731 .await?; 732 callee.post_return_async(store.as_context_mut()).await?; 733 Ok(ret0) 734 } 735 pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>( 736 &self, 737 mut store: S, 738 arg0: Flag2, 739 ) -> wasmtime::Result<Flag2> 740 where 741 <S as wasmtime::AsContext>::Data: Send, 742 { 743 let callee = unsafe { 744 wasmtime::component::TypedFunc::< 745 (Flag2,), 746 (Flag2,), 747 >::new_unchecked(self.roundtrip_flag2) 748 }; 749 let (ret0,) = callee 750 .call_async(store.as_context_mut(), (arg0,)) 751 .await?; 752 callee.post_return_async(store.as_context_mut()).await?; 753 Ok(ret0) 754 } 755 pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>( 756 &self, 757 mut store: S, 758 arg0: Flag4, 759 ) -> wasmtime::Result<Flag4> 760 where 761 <S as wasmtime::AsContext>::Data: Send, 762 { 763 let callee = unsafe { 764 wasmtime::component::TypedFunc::< 765 (Flag4,), 766 (Flag4,), 767 >::new_unchecked(self.roundtrip_flag4) 768 }; 769 let (ret0,) = callee 770 .call_async(store.as_context_mut(), (arg0,)) 771 .await?; 772 callee.post_return_async(store.as_context_mut()).await?; 773 Ok(ret0) 774 } 775 pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>( 776 &self, 777 mut store: S, 778 arg0: Flag8, 779 ) -> wasmtime::Result<Flag8> 780 where 781 <S as wasmtime::AsContext>::Data: Send, 782 { 783 let callee = unsafe { 784 wasmtime::component::TypedFunc::< 785 (Flag8,), 786 (Flag8,), 787 >::new_unchecked(self.roundtrip_flag8) 788 }; 789 let (ret0,) = callee 790 .call_async(store.as_context_mut(), (arg0,)) 791 .await?; 792 callee.post_return_async(store.as_context_mut()).await?; 793 Ok(ret0) 794 } 795 pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>( 796 &self, 797 mut store: S, 798 arg0: Flag16, 799 ) -> wasmtime::Result<Flag16> 800 where 801 <S as wasmtime::AsContext>::Data: Send, 802 { 803 let callee = unsafe { 804 wasmtime::component::TypedFunc::< 805 (Flag16,), 806 (Flag16,), 807 >::new_unchecked(self.roundtrip_flag16) 808 }; 809 let (ret0,) = callee 810 .call_async(store.as_context_mut(), (arg0,)) 811 .await?; 812 callee.post_return_async(store.as_context_mut()).await?; 813 Ok(ret0) 814 } 815 pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>( 816 &self, 817 mut store: S, 818 arg0: Flag32, 819 ) -> wasmtime::Result<Flag32> 820 where 821 <S as wasmtime::AsContext>::Data: Send, 822 { 823 let callee = unsafe { 824 wasmtime::component::TypedFunc::< 825 (Flag32,), 826 (Flag32,), 827 >::new_unchecked(self.roundtrip_flag32) 828 }; 829 let (ret0,) = callee 830 .call_async(store.as_context_mut(), (arg0,)) 831 .await?; 832 callee.post_return_async(store.as_context_mut()).await?; 833 Ok(ret0) 834 } 835 pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>( 836 &self, 837 mut store: S, 838 arg0: Flag64, 839 ) -> wasmtime::Result<Flag64> 840 where 841 <S as wasmtime::AsContext>::Data: Send, 842 { 843 let callee = unsafe { 844 wasmtime::component::TypedFunc::< 845 (Flag64,), 846 (Flag64,), 847 >::new_unchecked(self.roundtrip_flag64) 848 }; 849 let (ret0,) = callee 850 .call_async(store.as_context_mut(), (arg0,)) 851 .await?; 852 callee.post_return_async(store.as_context_mut()).await?; 853 Ok(ret0) 854 } 855 } 856 } 857 } 858 } 859 } 860