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