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