Path: blob/main/crates/component-macro/tests/expanded/flags_async.rs
1692 views
/// Auto-generated bindings for a pre-instantiated version of a1/// component which implements the world `the-flags`.2///3/// This structure is created through [`TheFlagsPre::new`] which4/// takes a [`InstancePre`](wasmtime::component::InstancePre) that5/// has been created through a [`Linker`](wasmtime::component::Linker).6///7/// For more information see [`TheFlags`] as well.8pub struct TheFlagsPre<T: 'static> {9instance_pre: wasmtime::component::InstancePre<T>,10indices: TheFlagsIndices,11}12impl<T: 'static> Clone for TheFlagsPre<T> {13fn clone(&self) -> Self {14Self {15instance_pre: self.instance_pre.clone(),16indices: self.indices.clone(),17}18}19}20impl<_T: 'static> TheFlagsPre<_T> {21/// Creates a new copy of `TheFlagsPre` bindings which can then22/// be used to instantiate into a particular store.23///24/// This method may fail if the component behind `instance_pre`25/// does not have the required exports.26pub fn new(27instance_pre: wasmtime::component::InstancePre<_T>,28) -> wasmtime::Result<Self> {29let indices = TheFlagsIndices::new(&instance_pre)?;30Ok(Self { instance_pre, indices })31}32pub fn engine(&self) -> &wasmtime::Engine {33self.instance_pre.engine()34}35pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {36&self.instance_pre37}38/// Instantiates a new instance of [`TheFlags`] within the39/// `store` provided.40///41/// This function will use `self` as the pre-instantiated42/// instance to perform instantiation. Afterwards the preloaded43/// indices in `self` are used to lookup all exports on the44/// resulting instance.45pub fn instantiate(46&self,47mut store: impl wasmtime::AsContextMut<Data = _T>,48) -> wasmtime::Result<TheFlags> {49let mut store = store.as_context_mut();50let instance = self.instance_pre.instantiate(&mut store)?;51self.indices.load(&mut store, &instance)52}53}54impl<_T: Send + 'static> TheFlagsPre<_T> {55/// Same as [`Self::instantiate`], except with `async`.56pub async fn instantiate_async(57&self,58mut store: impl wasmtime::AsContextMut<Data = _T>,59) -> wasmtime::Result<TheFlags> {60let mut store = store.as_context_mut();61let instance = self.instance_pre.instantiate_async(&mut store).await?;62self.indices.load(&mut store, &instance)63}64}65/// Auto-generated bindings for index of the exports of66/// `the-flags`.67///68/// This is an implementation detail of [`TheFlagsPre`] and can69/// be constructed if needed as well.70///71/// For more information see [`TheFlags`] as well.72#[derive(Clone)]73pub struct TheFlagsIndices {74interface0: exports::foo::foo::flegs::GuestIndices,75}76/// Auto-generated bindings for an instance a component which77/// implements the world `the-flags`.78///79/// This structure can be created through a number of means80/// depending on your requirements and what you have on hand:81///82/// * The most convenient way is to use83/// [`TheFlags::instantiate`] which only needs a84/// [`Store`], [`Component`], and [`Linker`].85///86/// * Alternatively you can create a [`TheFlagsPre`] ahead of87/// time with a [`Component`] to front-load string lookups88/// of exports once instead of per-instantiation. This89/// method then uses [`TheFlagsPre::instantiate`] to90/// create a [`TheFlags`].91///92/// * If you've instantiated the instance yourself already93/// then you can use [`TheFlags::new`].94///95/// These methods are all equivalent to one another and move96/// around the tradeoff of what work is performed when.97///98/// [`Store`]: wasmtime::Store99/// [`Component`]: wasmtime::component::Component100/// [`Linker`]: wasmtime::component::Linker101pub struct TheFlags {102interface0: exports::foo::foo::flegs::Guest,103}104const _: () = {105#[allow(unused_imports)]106use wasmtime::component::__internal::anyhow;107impl TheFlagsIndices {108/// Creates a new copy of `TheFlagsIndices` bindings which can then109/// be used to instantiate into a particular store.110///111/// This method may fail if the component does not have the112/// required exports.113pub fn new<_T>(114_instance_pre: &wasmtime::component::InstancePre<_T>,115) -> wasmtime::Result<Self> {116let _component = _instance_pre.component();117let _instance_type = _instance_pre.instance_type();118let interface0 = exports::foo::foo::flegs::GuestIndices::new(_instance_pre)?;119Ok(TheFlagsIndices { interface0 })120}121/// Uses the indices stored in `self` to load an instance122/// of [`TheFlags`] from the instance provided.123///124/// Note that at this time this method will additionally125/// perform type-checks of all exports.126pub fn load(127&self,128mut store: impl wasmtime::AsContextMut,129instance: &wasmtime::component::Instance,130) -> wasmtime::Result<TheFlags> {131let _ = &mut store;132let _instance = instance;133let interface0 = self.interface0.load(&mut store, &_instance)?;134Ok(TheFlags { interface0 })135}136}137impl TheFlags {138/// Convenience wrapper around [`TheFlagsPre::new`] and139/// [`TheFlagsPre::instantiate`].140pub fn instantiate<_T>(141store: impl wasmtime::AsContextMut<Data = _T>,142component: &wasmtime::component::Component,143linker: &wasmtime::component::Linker<_T>,144) -> wasmtime::Result<TheFlags> {145let pre = linker.instantiate_pre(component)?;146TheFlagsPre::new(pre)?.instantiate(store)147}148/// Convenience wrapper around [`TheFlagsIndices::new`] and149/// [`TheFlagsIndices::load`].150pub fn new(151mut store: impl wasmtime::AsContextMut,152instance: &wasmtime::component::Instance,153) -> wasmtime::Result<TheFlags> {154let indices = TheFlagsIndices::new(&instance.instance_pre(&store))?;155indices.load(&mut store, instance)156}157/// Convenience wrapper around [`TheFlagsPre::new`] and158/// [`TheFlagsPre::instantiate_async`].159pub async fn instantiate_async<_T>(160store: impl wasmtime::AsContextMut<Data = _T>,161component: &wasmtime::component::Component,162linker: &wasmtime::component::Linker<_T>,163) -> wasmtime::Result<TheFlags>164where165_T: Send,166{167let pre = linker.instantiate_pre(component)?;168TheFlagsPre::new(pre)?.instantiate_async(store).await169}170pub fn add_to_linker<T, D>(171linker: &mut wasmtime::component::Linker<T>,172host_getter: fn(&mut T) -> D::Data<'_>,173) -> wasmtime::Result<()>174where175D: foo::foo::flegs::HostWithStore + Send,176for<'a> D::Data<'a>: foo::foo::flegs::Host + Send,177T: 'static + Send,178{179foo::foo::flegs::add_to_linker::<T, D>(linker, host_getter)?;180Ok(())181}182pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest {183&self.interface0184}185}186};187pub mod foo {188pub mod foo {189#[allow(clippy::all)]190pub mod flegs {191#[allow(unused_imports)]192use wasmtime::component::__internal::{anyhow, Box};193wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; });194const _: () = {195assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32);196assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32);197};198wasmtime::component::flags!(199Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]200const B1; }201);202const _: () = {203assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32);204assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32);205};206wasmtime::component::flags!(207Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]208const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]209const B3; }210);211const _: () = {212assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32);213assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32);214};215wasmtime::component::flags!(216Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]217const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]218const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]219const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]220const B7; }221);222const _: () = {223assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32);224assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32);225};226wasmtime::component::flags!(227Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")]228const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]229const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]230const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]231const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]232const B9; #[component(name = "b10")] const B10; #[component(name =233"b11")] const B11; #[component(name = "b12")] const B12; #[component(name234= "b13")] const B13; #[component(name = "b14")] const B14;235#[component(name = "b15")] const B15; }236);237const _: () = {238assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32);239assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32);240};241wasmtime::component::flags!(242Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")]243const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]244const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]245const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]246const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]247const B9; #[component(name = "b10")] const B10; #[component(name =248"b11")] const B11; #[component(name = "b12")] const B12; #[component(name249= "b13")] const B13; #[component(name = "b14")] const B14;250#[component(name = "b15")] const B15; #[component(name = "b16")] const251B16; #[component(name = "b17")] const B17; #[component(name = "b18")]252const B18; #[component(name = "b19")] const B19; #[component(name =253"b20")] const B20; #[component(name = "b21")] const B21; #[component(name254= "b22")] const B22; #[component(name = "b23")] const B23;255#[component(name = "b24")] const B24; #[component(name = "b25")] const256B25; #[component(name = "b26")] const B26; #[component(name = "b27")]257const B27; #[component(name = "b28")] const B28; #[component(name =258"b29")] const B29; #[component(name = "b30")] const B30; #[component(name259= "b31")] const B31; }260);261const _: () = {262assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32);263assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32);264};265wasmtime::component::flags!(266Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")]267const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]268const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]269const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]270const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]271const B9; #[component(name = "b10")] const B10; #[component(name =272"b11")] const B11; #[component(name = "b12")] const B12; #[component(name273= "b13")] const B13; #[component(name = "b14")] const B14;274#[component(name = "b15")] const B15; #[component(name = "b16")] const275B16; #[component(name = "b17")] const B17; #[component(name = "b18")]276const B18; #[component(name = "b19")] const B19; #[component(name =277"b20")] const B20; #[component(name = "b21")] const B21; #[component(name278= "b22")] const B22; #[component(name = "b23")] const B23;279#[component(name = "b24")] const B24; #[component(name = "b25")] const280B25; #[component(name = "b26")] const B26; #[component(name = "b27")]281const B27; #[component(name = "b28")] const B28; #[component(name =282"b29")] const B29; #[component(name = "b30")] const B30; #[component(name283= "b31")] const B31; #[component(name = "b32")] const B32;284#[component(name = "b33")] const B33; #[component(name = "b34")] const285B34; #[component(name = "b35")] const B35; #[component(name = "b36")]286const B36; #[component(name = "b37")] const B37; #[component(name =287"b38")] const B38; #[component(name = "b39")] const B39; #[component(name288= "b40")] const B40; #[component(name = "b41")] const B41;289#[component(name = "b42")] const B42; #[component(name = "b43")] const290B43; #[component(name = "b44")] const B44; #[component(name = "b45")]291const B45; #[component(name = "b46")] const B46; #[component(name =292"b47")] const B47; #[component(name = "b48")] const B48; #[component(name293= "b49")] const B49; #[component(name = "b50")] const B50;294#[component(name = "b51")] const B51; #[component(name = "b52")] const295B52; #[component(name = "b53")] const B53; #[component(name = "b54")]296const B54; #[component(name = "b55")] const B55; #[component(name =297"b56")] const B56; #[component(name = "b57")] const B57; #[component(name298= "b58")] const B58; #[component(name = "b59")] const B59;299#[component(name = "b60")] const B60; #[component(name = "b61")] const300B61; #[component(name = "b62")] const B62; #[component(name = "b63")]301const B63; }302);303const _: () = {304assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32);305assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32);306};307pub trait HostWithStore: wasmtime::component::HasData + Send {}308impl<_T: ?Sized> HostWithStore for _T309where310_T: wasmtime::component::HasData + Send,311{}312pub trait Host: Send {313fn roundtrip_flag1(314&mut self,315x: Flag1,316) -> impl ::core::future::Future<Output = Flag1> + Send;317fn roundtrip_flag2(318&mut self,319x: Flag2,320) -> impl ::core::future::Future<Output = Flag2> + Send;321fn roundtrip_flag4(322&mut self,323x: Flag4,324) -> impl ::core::future::Future<Output = Flag4> + Send;325fn roundtrip_flag8(326&mut self,327x: Flag8,328) -> impl ::core::future::Future<Output = Flag8> + Send;329fn roundtrip_flag16(330&mut self,331x: Flag16,332) -> impl ::core::future::Future<Output = Flag16> + Send;333fn roundtrip_flag32(334&mut self,335x: Flag32,336) -> impl ::core::future::Future<Output = Flag32> + Send;337fn roundtrip_flag64(338&mut self,339x: Flag64,340) -> impl ::core::future::Future<Output = Flag64> + Send;341}342impl<_T: Host + ?Sized + Send> Host for &mut _T {343fn roundtrip_flag1(344&mut self,345x: Flag1,346) -> impl ::core::future::Future<Output = Flag1> + Send {347async move { Host::roundtrip_flag1(*self, x).await }348}349fn roundtrip_flag2(350&mut self,351x: Flag2,352) -> impl ::core::future::Future<Output = Flag2> + Send {353async move { Host::roundtrip_flag2(*self, x).await }354}355fn roundtrip_flag4(356&mut self,357x: Flag4,358) -> impl ::core::future::Future<Output = Flag4> + Send {359async move { Host::roundtrip_flag4(*self, x).await }360}361fn roundtrip_flag8(362&mut self,363x: Flag8,364) -> impl ::core::future::Future<Output = Flag8> + Send {365async move { Host::roundtrip_flag8(*self, x).await }366}367fn roundtrip_flag16(368&mut self,369x: Flag16,370) -> impl ::core::future::Future<Output = Flag16> + Send {371async move { Host::roundtrip_flag16(*self, x).await }372}373fn roundtrip_flag32(374&mut self,375x: Flag32,376) -> impl ::core::future::Future<Output = Flag32> + Send {377async move { Host::roundtrip_flag32(*self, x).await }378}379fn roundtrip_flag64(380&mut self,381x: Flag64,382) -> impl ::core::future::Future<Output = Flag64> + Send {383async move { Host::roundtrip_flag64(*self, x).await }384}385}386pub fn add_to_linker<T, D>(387linker: &mut wasmtime::component::Linker<T>,388host_getter: fn(&mut T) -> D::Data<'_>,389) -> wasmtime::Result<()>390where391D: HostWithStore,392for<'a> D::Data<'a>: Host,393T: 'static + Send,394{395let mut inst = linker.instance("foo:foo/flegs")?;396inst.func_wrap_async(397"roundtrip-flag1",398move |399mut caller: wasmtime::StoreContextMut<'_, T>,400(arg0,): (Flag1,)|401{402wasmtime::component::__internal::Box::new(async move {403let host = &mut host_getter(caller.data_mut());404let r = Host::roundtrip_flag1(host, arg0).await;405Ok((r,))406})407},408)?;409inst.func_wrap_async(410"roundtrip-flag2",411move |412mut caller: wasmtime::StoreContextMut<'_, T>,413(arg0,): (Flag2,)|414{415wasmtime::component::__internal::Box::new(async move {416let host = &mut host_getter(caller.data_mut());417let r = Host::roundtrip_flag2(host, arg0).await;418Ok((r,))419})420},421)?;422inst.func_wrap_async(423"roundtrip-flag4",424move |425mut caller: wasmtime::StoreContextMut<'_, T>,426(arg0,): (Flag4,)|427{428wasmtime::component::__internal::Box::new(async move {429let host = &mut host_getter(caller.data_mut());430let r = Host::roundtrip_flag4(host, arg0).await;431Ok((r,))432})433},434)?;435inst.func_wrap_async(436"roundtrip-flag8",437move |438mut caller: wasmtime::StoreContextMut<'_, T>,439(arg0,): (Flag8,)|440{441wasmtime::component::__internal::Box::new(async move {442let host = &mut host_getter(caller.data_mut());443let r = Host::roundtrip_flag8(host, arg0).await;444Ok((r,))445})446},447)?;448inst.func_wrap_async(449"roundtrip-flag16",450move |451mut caller: wasmtime::StoreContextMut<'_, T>,452(arg0,): (Flag16,)|453{454wasmtime::component::__internal::Box::new(async move {455let host = &mut host_getter(caller.data_mut());456let r = Host::roundtrip_flag16(host, arg0).await;457Ok((r,))458})459},460)?;461inst.func_wrap_async(462"roundtrip-flag32",463move |464mut caller: wasmtime::StoreContextMut<'_, T>,465(arg0,): (Flag32,)|466{467wasmtime::component::__internal::Box::new(async move {468let host = &mut host_getter(caller.data_mut());469let r = Host::roundtrip_flag32(host, arg0).await;470Ok((r,))471})472},473)?;474inst.func_wrap_async(475"roundtrip-flag64",476move |477mut caller: wasmtime::StoreContextMut<'_, T>,478(arg0,): (Flag64,)|479{480wasmtime::component::__internal::Box::new(async move {481let host = &mut host_getter(caller.data_mut());482let r = Host::roundtrip_flag64(host, arg0).await;483Ok((r,))484})485},486)?;487Ok(())488}489}490}491}492pub mod exports {493pub mod foo {494pub mod foo {495#[allow(clippy::all)]496pub mod flegs {497#[allow(unused_imports)]498use wasmtime::component::__internal::{anyhow, Box};499wasmtime::component::flags!(500Flag1 { #[component(name = "b0")] const B0; }501);502const _: () = {503assert!(5041 == < Flag1 as wasmtime::component::ComponentType >::SIZE32505);506assert!(5071 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32508);509};510wasmtime::component::flags!(511Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]512const B1; }513);514const _: () = {515assert!(5161 == < Flag2 as wasmtime::component::ComponentType >::SIZE32517);518assert!(5191 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32520);521};522wasmtime::component::flags!(523Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]524const B1; #[component(name = "b2")] const B2; #[component(name =525"b3")] const B3; }526);527const _: () = {528assert!(5291 == < Flag4 as wasmtime::component::ComponentType >::SIZE32530);531assert!(5321 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32533);534};535wasmtime::component::flags!(536Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]537const B1; #[component(name = "b2")] const B2; #[component(name =538"b3")] const B3; #[component(name = "b4")] const B4; #[component(name539= "b5")] const B5; #[component(name = "b6")] const B6;540#[component(name = "b7")] const B7; }541);542const _: () = {543assert!(5441 == < Flag8 as wasmtime::component::ComponentType >::SIZE32545);546assert!(5471 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32548);549};550wasmtime::component::flags!(551Flag16 { #[component(name = "b0")] const B0; #[component(name =552"b1")] const B1; #[component(name = "b2")] const B2; #[component(name553= "b3")] const B3; #[component(name = "b4")] const B4;554#[component(name = "b5")] const B5; #[component(name = "b6")] const555B6; #[component(name = "b7")] const B7; #[component(name = "b8")]556const B8; #[component(name = "b9")] const B9; #[component(name =557"b10")] const B10; #[component(name = "b11")] const B11;558#[component(name = "b12")] const B12; #[component(name = "b13")]559const B13; #[component(name = "b14")] const B14; #[component(name =560"b15")] const B15; }561);562const _: () = {563assert!(5642 == < Flag16 as wasmtime::component::ComponentType >::SIZE32565);566assert!(5672 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32568);569};570wasmtime::component::flags!(571Flag32 { #[component(name = "b0")] const B0; #[component(name =572"b1")] const B1; #[component(name = "b2")] const B2; #[component(name573= "b3")] const B3; #[component(name = "b4")] const B4;574#[component(name = "b5")] const B5; #[component(name = "b6")] const575B6; #[component(name = "b7")] const B7; #[component(name = "b8")]576const B8; #[component(name = "b9")] const B9; #[component(name =577"b10")] const B10; #[component(name = "b11")] const B11;578#[component(name = "b12")] const B12; #[component(name = "b13")]579const B13; #[component(name = "b14")] const B14; #[component(name =580"b15")] const B15; #[component(name = "b16")] const B16;581#[component(name = "b17")] const B17; #[component(name = "b18")]582const B18; #[component(name = "b19")] const B19; #[component(name =583"b20")] const B20; #[component(name = "b21")] const B21;584#[component(name = "b22")] const B22; #[component(name = "b23")]585const B23; #[component(name = "b24")] const B24; #[component(name =586"b25")] const B25; #[component(name = "b26")] const B26;587#[component(name = "b27")] const B27; #[component(name = "b28")]588const B28; #[component(name = "b29")] const B29; #[component(name =589"b30")] const B30; #[component(name = "b31")] const B31; }590);591const _: () = {592assert!(5934 == < Flag32 as wasmtime::component::ComponentType >::SIZE32594);595assert!(5964 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32597);598};599wasmtime::component::flags!(600Flag64 { #[component(name = "b0")] const B0; #[component(name =601"b1")] const B1; #[component(name = "b2")] const B2; #[component(name602= "b3")] const B3; #[component(name = "b4")] const B4;603#[component(name = "b5")] const B5; #[component(name = "b6")] const604B6; #[component(name = "b7")] const B7; #[component(name = "b8")]605const B8; #[component(name = "b9")] const B9; #[component(name =606"b10")] const B10; #[component(name = "b11")] const B11;607#[component(name = "b12")] const B12; #[component(name = "b13")]608const B13; #[component(name = "b14")] const B14; #[component(name =609"b15")] const B15; #[component(name = "b16")] const B16;610#[component(name = "b17")] const B17; #[component(name = "b18")]611const B18; #[component(name = "b19")] const B19; #[component(name =612"b20")] const B20; #[component(name = "b21")] const B21;613#[component(name = "b22")] const B22; #[component(name = "b23")]614const B23; #[component(name = "b24")] const B24; #[component(name =615"b25")] const B25; #[component(name = "b26")] const B26;616#[component(name = "b27")] const B27; #[component(name = "b28")]617const B28; #[component(name = "b29")] const B29; #[component(name =618"b30")] const B30; #[component(name = "b31")] const B31;619#[component(name = "b32")] const B32; #[component(name = "b33")]620const B33; #[component(name = "b34")] const B34; #[component(name =621"b35")] const B35; #[component(name = "b36")] const B36;622#[component(name = "b37")] const B37; #[component(name = "b38")]623const B38; #[component(name = "b39")] const B39; #[component(name =624"b40")] const B40; #[component(name = "b41")] const B41;625#[component(name = "b42")] const B42; #[component(name = "b43")]626const B43; #[component(name = "b44")] const B44; #[component(name =627"b45")] const B45; #[component(name = "b46")] const B46;628#[component(name = "b47")] const B47; #[component(name = "b48")]629const B48; #[component(name = "b49")] const B49; #[component(name =630"b50")] const B50; #[component(name = "b51")] const B51;631#[component(name = "b52")] const B52; #[component(name = "b53")]632const B53; #[component(name = "b54")] const B54; #[component(name =633"b55")] const B55; #[component(name = "b56")] const B56;634#[component(name = "b57")] const B57; #[component(name = "b58")]635const B58; #[component(name = "b59")] const B59; #[component(name =636"b60")] const B60; #[component(name = "b61")] const B61;637#[component(name = "b62")] const B62; #[component(name = "b63")]638const B63; }639);640const _: () = {641assert!(6428 == < Flag64 as wasmtime::component::ComponentType >::SIZE32643);644assert!(6454 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32646);647};648pub struct Guest {649roundtrip_flag1: wasmtime::component::Func,650roundtrip_flag2: wasmtime::component::Func,651roundtrip_flag4: wasmtime::component::Func,652roundtrip_flag8: wasmtime::component::Func,653roundtrip_flag16: wasmtime::component::Func,654roundtrip_flag32: wasmtime::component::Func,655roundtrip_flag64: wasmtime::component::Func,656}657#[derive(Clone)]658pub struct GuestIndices {659roundtrip_flag1: wasmtime::component::ComponentExportIndex,660roundtrip_flag2: wasmtime::component::ComponentExportIndex,661roundtrip_flag4: wasmtime::component::ComponentExportIndex,662roundtrip_flag8: wasmtime::component::ComponentExportIndex,663roundtrip_flag16: wasmtime::component::ComponentExportIndex,664roundtrip_flag32: wasmtime::component::ComponentExportIndex,665roundtrip_flag64: wasmtime::component::ComponentExportIndex,666}667impl GuestIndices {668/// Constructor for [`GuestIndices`] which takes a669/// [`Component`](wasmtime::component::Component) as input and can be executed670/// before instantiation.671///672/// This constructor can be used to front-load string lookups to find exports673/// within a component.674pub fn new<_T>(675_instance_pre: &wasmtime::component::InstancePre<_T>,676) -> wasmtime::Result<GuestIndices> {677let instance = _instance_pre678.component()679.get_export_index(None, "foo:foo/flegs")680.ok_or_else(|| {681anyhow::anyhow!(682"no exported instance named `foo:foo/flegs`"683)684})?;685let mut lookup = move |name| {686_instance_pre687.component()688.get_export_index(Some(&instance), name)689.ok_or_else(|| {690anyhow::anyhow!(691"instance export `foo:foo/flegs` does \692not have export `{name}`"693)694})695};696let _ = &mut lookup;697let roundtrip_flag1 = lookup("roundtrip-flag1")?;698let roundtrip_flag2 = lookup("roundtrip-flag2")?;699let roundtrip_flag4 = lookup("roundtrip-flag4")?;700let roundtrip_flag8 = lookup("roundtrip-flag8")?;701let roundtrip_flag16 = lookup("roundtrip-flag16")?;702let roundtrip_flag32 = lookup("roundtrip-flag32")?;703let roundtrip_flag64 = lookup("roundtrip-flag64")?;704Ok(GuestIndices {705roundtrip_flag1,706roundtrip_flag2,707roundtrip_flag4,708roundtrip_flag8,709roundtrip_flag16,710roundtrip_flag32,711roundtrip_flag64,712})713}714pub fn load(715&self,716mut store: impl wasmtime::AsContextMut,717instance: &wasmtime::component::Instance,718) -> wasmtime::Result<Guest> {719let _instance = instance;720let _instance_pre = _instance.instance_pre(&store);721let _instance_type = _instance_pre.instance_type();722let mut store = store.as_context_mut();723let _ = &mut store;724let roundtrip_flag1 = *_instance725.get_typed_func::<726(Flag1,),727(Flag1,),728>(&mut store, &self.roundtrip_flag1)?729.func();730let roundtrip_flag2 = *_instance731.get_typed_func::<732(Flag2,),733(Flag2,),734>(&mut store, &self.roundtrip_flag2)?735.func();736let roundtrip_flag4 = *_instance737.get_typed_func::<738(Flag4,),739(Flag4,),740>(&mut store, &self.roundtrip_flag4)?741.func();742let roundtrip_flag8 = *_instance743.get_typed_func::<744(Flag8,),745(Flag8,),746>(&mut store, &self.roundtrip_flag8)?747.func();748let roundtrip_flag16 = *_instance749.get_typed_func::<750(Flag16,),751(Flag16,),752>(&mut store, &self.roundtrip_flag16)?753.func();754let roundtrip_flag32 = *_instance755.get_typed_func::<756(Flag32,),757(Flag32,),758>(&mut store, &self.roundtrip_flag32)?759.func();760let roundtrip_flag64 = *_instance761.get_typed_func::<762(Flag64,),763(Flag64,),764>(&mut store, &self.roundtrip_flag64)?765.func();766Ok(Guest {767roundtrip_flag1,768roundtrip_flag2,769roundtrip_flag4,770roundtrip_flag8,771roundtrip_flag16,772roundtrip_flag32,773roundtrip_flag64,774})775}776}777impl Guest {778pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(779&self,780mut store: S,781arg0: Flag1,782) -> wasmtime::Result<Flag1>783where784<S as wasmtime::AsContext>::Data: Send,785{786let callee = unsafe {787wasmtime::component::TypedFunc::<788(Flag1,),789(Flag1,),790>::new_unchecked(self.roundtrip_flag1)791};792let (ret0,) = callee793.call_async(store.as_context_mut(), (arg0,))794.await?;795callee.post_return_async(store.as_context_mut()).await?;796Ok(ret0)797}798pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(799&self,800mut store: S,801arg0: Flag2,802) -> wasmtime::Result<Flag2>803where804<S as wasmtime::AsContext>::Data: Send,805{806let callee = unsafe {807wasmtime::component::TypedFunc::<808(Flag2,),809(Flag2,),810>::new_unchecked(self.roundtrip_flag2)811};812let (ret0,) = callee813.call_async(store.as_context_mut(), (arg0,))814.await?;815callee.post_return_async(store.as_context_mut()).await?;816Ok(ret0)817}818pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(819&self,820mut store: S,821arg0: Flag4,822) -> wasmtime::Result<Flag4>823where824<S as wasmtime::AsContext>::Data: Send,825{826let callee = unsafe {827wasmtime::component::TypedFunc::<828(Flag4,),829(Flag4,),830>::new_unchecked(self.roundtrip_flag4)831};832let (ret0,) = callee833.call_async(store.as_context_mut(), (arg0,))834.await?;835callee.post_return_async(store.as_context_mut()).await?;836Ok(ret0)837}838pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(839&self,840mut store: S,841arg0: Flag8,842) -> wasmtime::Result<Flag8>843where844<S as wasmtime::AsContext>::Data: Send,845{846let callee = unsafe {847wasmtime::component::TypedFunc::<848(Flag8,),849(Flag8,),850>::new_unchecked(self.roundtrip_flag8)851};852let (ret0,) = callee853.call_async(store.as_context_mut(), (arg0,))854.await?;855callee.post_return_async(store.as_context_mut()).await?;856Ok(ret0)857}858pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(859&self,860mut store: S,861arg0: Flag16,862) -> wasmtime::Result<Flag16>863where864<S as wasmtime::AsContext>::Data: Send,865{866let callee = unsafe {867wasmtime::component::TypedFunc::<868(Flag16,),869(Flag16,),870>::new_unchecked(self.roundtrip_flag16)871};872let (ret0,) = callee873.call_async(store.as_context_mut(), (arg0,))874.await?;875callee.post_return_async(store.as_context_mut()).await?;876Ok(ret0)877}878pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(879&self,880mut store: S,881arg0: Flag32,882) -> wasmtime::Result<Flag32>883where884<S as wasmtime::AsContext>::Data: Send,885{886let callee = unsafe {887wasmtime::component::TypedFunc::<888(Flag32,),889(Flag32,),890>::new_unchecked(self.roundtrip_flag32)891};892let (ret0,) = callee893.call_async(store.as_context_mut(), (arg0,))894.await?;895callee.post_return_async(store.as_context_mut()).await?;896Ok(ret0)897}898pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(899&self,900mut store: S,901arg0: Flag64,902) -> wasmtime::Result<Flag64>903where904<S as wasmtime::AsContext>::Data: Send,905{906let callee = unsafe {907wasmtime::component::TypedFunc::<908(Flag64,),909(Flag64,),910>::new_unchecked(self.roundtrip_flag64)911};912let (ret0,) = callee913.call_async(store.as_context_mut(), (arg0,))914.await?;915callee.post_return_async(store.as_context_mut()).await?;916Ok(ret0)917}918}919}920}921}922}923924925