Path: blob/main/crates/component-macro/tests/expanded/flags_async.rs
3068 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 _: () = {105impl TheFlagsIndices {106/// Creates a new copy of `TheFlagsIndices` bindings which can then107/// be used to instantiate into a particular store.108///109/// This method may fail if the component does not have the110/// required exports.111pub fn new<_T>(112_instance_pre: &wasmtime::component::InstancePre<_T>,113) -> wasmtime::Result<Self> {114let _component = _instance_pre.component();115let _instance_type = _instance_pre.instance_type();116let interface0 = exports::foo::foo::flegs::GuestIndices::new(_instance_pre)?;117Ok(TheFlagsIndices { interface0 })118}119/// Uses the indices stored in `self` to load an instance120/// of [`TheFlags`] from the instance provided.121///122/// Note that at this time this method will additionally123/// perform type-checks of all exports.124pub fn load(125&self,126mut store: impl wasmtime::AsContextMut,127instance: &wasmtime::component::Instance,128) -> wasmtime::Result<TheFlags> {129let _ = &mut store;130let _instance = instance;131let interface0 = self.interface0.load(&mut store, &_instance)?;132Ok(TheFlags { interface0 })133}134}135impl TheFlags {136/// Convenience wrapper around [`TheFlagsPre::new`] and137/// [`TheFlagsPre::instantiate`].138pub fn instantiate<_T>(139store: impl wasmtime::AsContextMut<Data = _T>,140component: &wasmtime::component::Component,141linker: &wasmtime::component::Linker<_T>,142) -> wasmtime::Result<TheFlags> {143let pre = linker.instantiate_pre(component)?;144TheFlagsPre::new(pre)?.instantiate(store)145}146/// Convenience wrapper around [`TheFlagsIndices::new`] and147/// [`TheFlagsIndices::load`].148pub fn new(149mut store: impl wasmtime::AsContextMut,150instance: &wasmtime::component::Instance,151) -> wasmtime::Result<TheFlags> {152let indices = TheFlagsIndices::new(&instance.instance_pre(&store))?;153indices.load(&mut store, instance)154}155/// Convenience wrapper around [`TheFlagsPre::new`] and156/// [`TheFlagsPre::instantiate_async`].157pub async fn instantiate_async<_T>(158store: impl wasmtime::AsContextMut<Data = _T>,159component: &wasmtime::component::Component,160linker: &wasmtime::component::Linker<_T>,161) -> wasmtime::Result<TheFlags>162where163_T: Send,164{165let pre = linker.instantiate_pre(component)?;166TheFlagsPre::new(pre)?.instantiate_async(store).await167}168pub fn add_to_linker<T, D>(169linker: &mut wasmtime::component::Linker<T>,170host_getter: fn(&mut T) -> D::Data<'_>,171) -> wasmtime::Result<()>172where173D: foo::foo::flegs::HostWithStore + Send,174for<'a> D::Data<'a>: foo::foo::flegs::Host + Send,175T: 'static + Send,176{177foo::foo::flegs::add_to_linker::<T, D>(linker, host_getter)?;178Ok(())179}180pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest {181&self.interface0182}183}184};185pub mod foo {186pub mod foo {187#[allow(clippy::all)]188pub mod flegs {189#[allow(unused_imports)]190use wasmtime::component::__internal::Box;191wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; });192const _: () = {193assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32);194assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32);195};196wasmtime::component::flags!(197Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]198const B1; }199);200const _: () = {201assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32);202assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32);203};204wasmtime::component::flags!(205Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]206const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]207const B3; }208);209const _: () = {210assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32);211assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32);212};213wasmtime::component::flags!(214Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]215const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]216const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]217const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]218const B7; }219);220const _: () = {221assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32);222assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32);223};224wasmtime::component::flags!(225Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")]226const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]227const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]228const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]229const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]230const B9; #[component(name = "b10")] const B10; #[component(name =231"b11")] const B11; #[component(name = "b12")] const B12; #[component(name232= "b13")] const B13; #[component(name = "b14")] const B14;233#[component(name = "b15")] const B15; }234);235const _: () = {236assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32);237assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32);238};239wasmtime::component::flags!(240Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")]241const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]242const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]243const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]244const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]245const B9; #[component(name = "b10")] const B10; #[component(name =246"b11")] const B11; #[component(name = "b12")] const B12; #[component(name247= "b13")] const B13; #[component(name = "b14")] const B14;248#[component(name = "b15")] const B15; #[component(name = "b16")] const249B16; #[component(name = "b17")] const B17; #[component(name = "b18")]250const B18; #[component(name = "b19")] const B19; #[component(name =251"b20")] const B20; #[component(name = "b21")] const B21; #[component(name252= "b22")] const B22; #[component(name = "b23")] const B23;253#[component(name = "b24")] const B24; #[component(name = "b25")] const254B25; #[component(name = "b26")] const B26; #[component(name = "b27")]255const B27; #[component(name = "b28")] const B28; #[component(name =256"b29")] const B29; #[component(name = "b30")] const B30; #[component(name257= "b31")] const B31; }258);259const _: () = {260assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32);261assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32);262};263wasmtime::component::flags!(264Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")]265const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]266const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]267const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]268const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]269const B9; #[component(name = "b10")] const B10; #[component(name =270"b11")] const B11; #[component(name = "b12")] const B12; #[component(name271= "b13")] const B13; #[component(name = "b14")] const B14;272#[component(name = "b15")] const B15; #[component(name = "b16")] const273B16; #[component(name = "b17")] const B17; #[component(name = "b18")]274const B18; #[component(name = "b19")] const B19; #[component(name =275"b20")] const B20; #[component(name = "b21")] const B21; #[component(name276= "b22")] const B22; #[component(name = "b23")] const B23;277#[component(name = "b24")] const B24; #[component(name = "b25")] const278B25; #[component(name = "b26")] const B26; #[component(name = "b27")]279const B27; #[component(name = "b28")] const B28; #[component(name =280"b29")] const B29; #[component(name = "b30")] const B30; #[component(name281= "b31")] const B31; #[component(name = "b32")] const B32;282#[component(name = "b33")] const B33; #[component(name = "b34")] const283B34; #[component(name = "b35")] const B35; #[component(name = "b36")]284const B36; #[component(name = "b37")] const B37; #[component(name =285"b38")] const B38; #[component(name = "b39")] const B39; #[component(name286= "b40")] const B40; #[component(name = "b41")] const B41;287#[component(name = "b42")] const B42; #[component(name = "b43")] const288B43; #[component(name = "b44")] const B44; #[component(name = "b45")]289const B45; #[component(name = "b46")] const B46; #[component(name =290"b47")] const B47; #[component(name = "b48")] const B48; #[component(name291= "b49")] const B49; #[component(name = "b50")] const B50;292#[component(name = "b51")] const B51; #[component(name = "b52")] const293B52; #[component(name = "b53")] const B53; #[component(name = "b54")]294const B54; #[component(name = "b55")] const B55; #[component(name =295"b56")] const B56; #[component(name = "b57")] const B57; #[component(name296= "b58")] const B58; #[component(name = "b59")] const B59;297#[component(name = "b60")] const B60; #[component(name = "b61")] const298B61; #[component(name = "b62")] const B62; #[component(name = "b63")]299const B63; }300);301const _: () = {302assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32);303assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32);304};305pub trait HostWithStore: wasmtime::component::HasData + Send {}306impl<_T: ?Sized> HostWithStore for _T307where308_T: wasmtime::component::HasData + Send,309{}310pub trait Host: Send {311fn roundtrip_flag1(312&mut self,313x: Flag1,314) -> impl ::core::future::Future<Output = Flag1> + Send;315fn roundtrip_flag2(316&mut self,317x: Flag2,318) -> impl ::core::future::Future<Output = Flag2> + Send;319fn roundtrip_flag4(320&mut self,321x: Flag4,322) -> impl ::core::future::Future<Output = Flag4> + Send;323fn roundtrip_flag8(324&mut self,325x: Flag8,326) -> impl ::core::future::Future<Output = Flag8> + Send;327fn roundtrip_flag16(328&mut self,329x: Flag16,330) -> impl ::core::future::Future<Output = Flag16> + Send;331fn roundtrip_flag32(332&mut self,333x: Flag32,334) -> impl ::core::future::Future<Output = Flag32> + Send;335fn roundtrip_flag64(336&mut self,337x: Flag64,338) -> impl ::core::future::Future<Output = Flag64> + Send;339}340impl<_T: Host + ?Sized + Send> Host for &mut _T {341fn roundtrip_flag1(342&mut self,343x: Flag1,344) -> impl ::core::future::Future<Output = Flag1> + Send {345async move { Host::roundtrip_flag1(*self, x).await }346}347fn roundtrip_flag2(348&mut self,349x: Flag2,350) -> impl ::core::future::Future<Output = Flag2> + Send {351async move { Host::roundtrip_flag2(*self, x).await }352}353fn roundtrip_flag4(354&mut self,355x: Flag4,356) -> impl ::core::future::Future<Output = Flag4> + Send {357async move { Host::roundtrip_flag4(*self, x).await }358}359fn roundtrip_flag8(360&mut self,361x: Flag8,362) -> impl ::core::future::Future<Output = Flag8> + Send {363async move { Host::roundtrip_flag8(*self, x).await }364}365fn roundtrip_flag16(366&mut self,367x: Flag16,368) -> impl ::core::future::Future<Output = Flag16> + Send {369async move { Host::roundtrip_flag16(*self, x).await }370}371fn roundtrip_flag32(372&mut self,373x: Flag32,374) -> impl ::core::future::Future<Output = Flag32> + Send {375async move { Host::roundtrip_flag32(*self, x).await }376}377fn roundtrip_flag64(378&mut self,379x: Flag64,380) -> impl ::core::future::Future<Output = Flag64> + Send {381async move { Host::roundtrip_flag64(*self, x).await }382}383}384pub fn add_to_linker<T, D>(385linker: &mut wasmtime::component::Linker<T>,386host_getter: fn(&mut T) -> D::Data<'_>,387) -> wasmtime::Result<()>388where389D: HostWithStore,390for<'a> D::Data<'a>: Host,391T: 'static + Send,392{393let mut inst = linker.instance("foo:foo/flegs")?;394inst.func_wrap_async(395"roundtrip-flag1",396move |397mut caller: wasmtime::StoreContextMut<'_, T>,398(arg0,): (Flag1,)|399{400wasmtime::component::__internal::Box::new(async move {401let host = &mut host_getter(caller.data_mut());402let r = Host::roundtrip_flag1(host, arg0).await;403Ok((r,))404})405},406)?;407inst.func_wrap_async(408"roundtrip-flag2",409move |410mut caller: wasmtime::StoreContextMut<'_, T>,411(arg0,): (Flag2,)|412{413wasmtime::component::__internal::Box::new(async move {414let host = &mut host_getter(caller.data_mut());415let r = Host::roundtrip_flag2(host, arg0).await;416Ok((r,))417})418},419)?;420inst.func_wrap_async(421"roundtrip-flag4",422move |423mut caller: wasmtime::StoreContextMut<'_, T>,424(arg0,): (Flag4,)|425{426wasmtime::component::__internal::Box::new(async move {427let host = &mut host_getter(caller.data_mut());428let r = Host::roundtrip_flag4(host, arg0).await;429Ok((r,))430})431},432)?;433inst.func_wrap_async(434"roundtrip-flag8",435move |436mut caller: wasmtime::StoreContextMut<'_, T>,437(arg0,): (Flag8,)|438{439wasmtime::component::__internal::Box::new(async move {440let host = &mut host_getter(caller.data_mut());441let r = Host::roundtrip_flag8(host, arg0).await;442Ok((r,))443})444},445)?;446inst.func_wrap_async(447"roundtrip-flag16",448move |449mut caller: wasmtime::StoreContextMut<'_, T>,450(arg0,): (Flag16,)|451{452wasmtime::component::__internal::Box::new(async move {453let host = &mut host_getter(caller.data_mut());454let r = Host::roundtrip_flag16(host, arg0).await;455Ok((r,))456})457},458)?;459inst.func_wrap_async(460"roundtrip-flag32",461move |462mut caller: wasmtime::StoreContextMut<'_, T>,463(arg0,): (Flag32,)|464{465wasmtime::component::__internal::Box::new(async move {466let host = &mut host_getter(caller.data_mut());467let r = Host::roundtrip_flag32(host, arg0).await;468Ok((r,))469})470},471)?;472inst.func_wrap_async(473"roundtrip-flag64",474move |475mut caller: wasmtime::StoreContextMut<'_, T>,476(arg0,): (Flag64,)|477{478wasmtime::component::__internal::Box::new(async move {479let host = &mut host_getter(caller.data_mut());480let r = Host::roundtrip_flag64(host, arg0).await;481Ok((r,))482})483},484)?;485Ok(())486}487}488}489}490pub mod exports {491pub mod foo {492pub mod foo {493#[allow(clippy::all)]494pub mod flegs {495#[allow(unused_imports)]496use wasmtime::component::__internal::Box;497wasmtime::component::flags!(498Flag1 { #[component(name = "b0")] const B0; }499);500const _: () = {501assert!(5021 == < Flag1 as wasmtime::component::ComponentType >::SIZE32503);504assert!(5051 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32506);507};508wasmtime::component::flags!(509Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]510const B1; }511);512const _: () = {513assert!(5141 == < Flag2 as wasmtime::component::ComponentType >::SIZE32515);516assert!(5171 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32518);519};520wasmtime::component::flags!(521Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]522const B1; #[component(name = "b2")] const B2; #[component(name =523"b3")] const B3; }524);525const _: () = {526assert!(5271 == < Flag4 as wasmtime::component::ComponentType >::SIZE32528);529assert!(5301 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32531);532};533wasmtime::component::flags!(534Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]535const B1; #[component(name = "b2")] const B2; #[component(name =536"b3")] const B3; #[component(name = "b4")] const B4; #[component(name537= "b5")] const B5; #[component(name = "b6")] const B6;538#[component(name = "b7")] const B7; }539);540const _: () = {541assert!(5421 == < Flag8 as wasmtime::component::ComponentType >::SIZE32543);544assert!(5451 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32546);547};548wasmtime::component::flags!(549Flag16 { #[component(name = "b0")] const B0; #[component(name =550"b1")] const B1; #[component(name = "b2")] const B2; #[component(name551= "b3")] const B3; #[component(name = "b4")] const B4;552#[component(name = "b5")] const B5; #[component(name = "b6")] const553B6; #[component(name = "b7")] const B7; #[component(name = "b8")]554const 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")]557const B13; #[component(name = "b14")] const B14; #[component(name =558"b15")] const B15; }559);560const _: () = {561assert!(5622 == < Flag16 as wasmtime::component::ComponentType >::SIZE32563);564assert!(5652 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32566);567};568wasmtime::component::flags!(569Flag32 { #[component(name = "b0")] const B0; #[component(name =570"b1")] const B1; #[component(name = "b2")] const B2; #[component(name571= "b3")] const B3; #[component(name = "b4")] const B4;572#[component(name = "b5")] const B5; #[component(name = "b6")] const573B6; #[component(name = "b7")] const B7; #[component(name = "b8")]574const B8; #[component(name = "b9")] const B9; #[component(name =575"b10")] const B10; #[component(name = "b11")] const B11;576#[component(name = "b12")] const B12; #[component(name = "b13")]577const B13; #[component(name = "b14")] const B14; #[component(name =578"b15")] const B15; #[component(name = "b16")] const B16;579#[component(name = "b17")] const B17; #[component(name = "b18")]580const B18; #[component(name = "b19")] const B19; #[component(name =581"b20")] const B20; #[component(name = "b21")] const B21;582#[component(name = "b22")] const B22; #[component(name = "b23")]583const B23; #[component(name = "b24")] const B24; #[component(name =584"b25")] const B25; #[component(name = "b26")] const B26;585#[component(name = "b27")] const B27; #[component(name = "b28")]586const B28; #[component(name = "b29")] const B29; #[component(name =587"b30")] const B30; #[component(name = "b31")] const B31; }588);589const _: () = {590assert!(5914 == < Flag32 as wasmtime::component::ComponentType >::SIZE32592);593assert!(5944 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32595);596};597wasmtime::component::flags!(598Flag64 { #[component(name = "b0")] const B0; #[component(name =599"b1")] const B1; #[component(name = "b2")] const B2; #[component(name600= "b3")] const B3; #[component(name = "b4")] const B4;601#[component(name = "b5")] const B5; #[component(name = "b6")] const602B6; #[component(name = "b7")] const B7; #[component(name = "b8")]603const B8; #[component(name = "b9")] const B9; #[component(name =604"b10")] const B10; #[component(name = "b11")] const B11;605#[component(name = "b12")] const B12; #[component(name = "b13")]606const B13; #[component(name = "b14")] const B14; #[component(name =607"b15")] const B15; #[component(name = "b16")] const B16;608#[component(name = "b17")] const B17; #[component(name = "b18")]609const B18; #[component(name = "b19")] const B19; #[component(name =610"b20")] const B20; #[component(name = "b21")] const B21;611#[component(name = "b22")] const B22; #[component(name = "b23")]612const B23; #[component(name = "b24")] const B24; #[component(name =613"b25")] const B25; #[component(name = "b26")] const B26;614#[component(name = "b27")] const B27; #[component(name = "b28")]615const B28; #[component(name = "b29")] const B29; #[component(name =616"b30")] const B30; #[component(name = "b31")] const B31;617#[component(name = "b32")] const B32; #[component(name = "b33")]618const B33; #[component(name = "b34")] const B34; #[component(name =619"b35")] const B35; #[component(name = "b36")] const B36;620#[component(name = "b37")] const B37; #[component(name = "b38")]621const B38; #[component(name = "b39")] const B39; #[component(name =622"b40")] const B40; #[component(name = "b41")] const B41;623#[component(name = "b42")] const B42; #[component(name = "b43")]624const B43; #[component(name = "b44")] const B44; #[component(name =625"b45")] const B45; #[component(name = "b46")] const B46;626#[component(name = "b47")] const B47; #[component(name = "b48")]627const B48; #[component(name = "b49")] const B49; #[component(name =628"b50")] const B50; #[component(name = "b51")] const B51;629#[component(name = "b52")] const B52; #[component(name = "b53")]630const B53; #[component(name = "b54")] const B54; #[component(name =631"b55")] const B55; #[component(name = "b56")] const B56;632#[component(name = "b57")] const B57; #[component(name = "b58")]633const B58; #[component(name = "b59")] const B59; #[component(name =634"b60")] const B60; #[component(name = "b61")] const B61;635#[component(name = "b62")] const B62; #[component(name = "b63")]636const B63; }637);638const _: () = {639assert!(6408 == < Flag64 as wasmtime::component::ComponentType >::SIZE32641);642assert!(6434 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32644);645};646#[derive(Clone)]647pub struct Guest {648roundtrip_flag1: wasmtime::component::Func,649roundtrip_flag2: wasmtime::component::Func,650roundtrip_flag4: wasmtime::component::Func,651roundtrip_flag8: wasmtime::component::Func,652roundtrip_flag16: wasmtime::component::Func,653roundtrip_flag32: wasmtime::component::Func,654roundtrip_flag64: wasmtime::component::Func,655}656#[derive(Clone)]657pub struct GuestIndices {658roundtrip_flag1: wasmtime::component::ComponentExportIndex,659roundtrip_flag2: wasmtime::component::ComponentExportIndex,660roundtrip_flag4: wasmtime::component::ComponentExportIndex,661roundtrip_flag8: wasmtime::component::ComponentExportIndex,662roundtrip_flag16: wasmtime::component::ComponentExportIndex,663roundtrip_flag32: wasmtime::component::ComponentExportIndex,664roundtrip_flag64: wasmtime::component::ComponentExportIndex,665}666impl GuestIndices {667/// Constructor for [`GuestIndices`] which takes a668/// [`Component`](wasmtime::component::Component) as input and can be executed669/// before instantiation.670///671/// This constructor can be used to front-load string lookups to find exports672/// within a component.673pub fn new<_T>(674_instance_pre: &wasmtime::component::InstancePre<_T>,675) -> wasmtime::Result<GuestIndices> {676let instance = _instance_pre677.component()678.get_export_index(None, "foo:foo/flegs")679.ok_or_else(|| {680wasmtime::format_err!(681"no exported instance named `foo:foo/flegs`"682)683})?;684let mut lookup = move |name| {685_instance_pre686.component()687.get_export_index(Some(&instance), name)688.ok_or_else(|| {689wasmtime::format_err!(690"instance export `foo:foo/flegs` does \691not have export `{name}`"692)693})694};695let _ = &mut lookup;696let roundtrip_flag1 = lookup("roundtrip-flag1")?;697let roundtrip_flag2 = lookup("roundtrip-flag2")?;698let roundtrip_flag4 = lookup("roundtrip-flag4")?;699let roundtrip_flag8 = lookup("roundtrip-flag8")?;700let roundtrip_flag16 = lookup("roundtrip-flag16")?;701let roundtrip_flag32 = lookup("roundtrip-flag32")?;702let roundtrip_flag64 = lookup("roundtrip-flag64")?;703Ok(GuestIndices {704roundtrip_flag1,705roundtrip_flag2,706roundtrip_flag4,707roundtrip_flag8,708roundtrip_flag16,709roundtrip_flag32,710roundtrip_flag64,711})712}713pub fn load(714&self,715mut store: impl wasmtime::AsContextMut,716instance: &wasmtime::component::Instance,717) -> wasmtime::Result<Guest> {718let _instance = instance;719let _instance_pre = _instance.instance_pre(&store);720let _instance_type = _instance_pre.instance_type();721let mut store = store.as_context_mut();722let _ = &mut store;723let roundtrip_flag1 = *_instance724.get_typed_func::<725(Flag1,),726(Flag1,),727>(&mut store, &self.roundtrip_flag1)?728.func();729let roundtrip_flag2 = *_instance730.get_typed_func::<731(Flag2,),732(Flag2,),733>(&mut store, &self.roundtrip_flag2)?734.func();735let roundtrip_flag4 = *_instance736.get_typed_func::<737(Flag4,),738(Flag4,),739>(&mut store, &self.roundtrip_flag4)?740.func();741let roundtrip_flag8 = *_instance742.get_typed_func::<743(Flag8,),744(Flag8,),745>(&mut store, &self.roundtrip_flag8)?746.func();747let roundtrip_flag16 = *_instance748.get_typed_func::<749(Flag16,),750(Flag16,),751>(&mut store, &self.roundtrip_flag16)?752.func();753let roundtrip_flag32 = *_instance754.get_typed_func::<755(Flag32,),756(Flag32,),757>(&mut store, &self.roundtrip_flag32)?758.func();759let roundtrip_flag64 = *_instance760.get_typed_func::<761(Flag64,),762(Flag64,),763>(&mut store, &self.roundtrip_flag64)?764.func();765Ok(Guest {766roundtrip_flag1,767roundtrip_flag2,768roundtrip_flag4,769roundtrip_flag8,770roundtrip_flag16,771roundtrip_flag32,772roundtrip_flag64,773})774}775}776impl Guest {777pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(778&self,779mut store: S,780arg0: Flag1,781) -> wasmtime::Result<Flag1>782where783<S as wasmtime::AsContext>::Data: Send,784{785let callee = unsafe {786wasmtime::component::TypedFunc::<787(Flag1,),788(Flag1,),789>::new_unchecked(self.roundtrip_flag1)790};791let (ret0,) = callee792.call_async(store.as_context_mut(), (arg0,))793.await?;794Ok(ret0)795}796pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(797&self,798mut store: S,799arg0: Flag2,800) -> wasmtime::Result<Flag2>801where802<S as wasmtime::AsContext>::Data: Send,803{804let callee = unsafe {805wasmtime::component::TypedFunc::<806(Flag2,),807(Flag2,),808>::new_unchecked(self.roundtrip_flag2)809};810let (ret0,) = callee811.call_async(store.as_context_mut(), (arg0,))812.await?;813Ok(ret0)814}815pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(816&self,817mut store: S,818arg0: Flag4,819) -> wasmtime::Result<Flag4>820where821<S as wasmtime::AsContext>::Data: Send,822{823let callee = unsafe {824wasmtime::component::TypedFunc::<825(Flag4,),826(Flag4,),827>::new_unchecked(self.roundtrip_flag4)828};829let (ret0,) = callee830.call_async(store.as_context_mut(), (arg0,))831.await?;832Ok(ret0)833}834pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(835&self,836mut store: S,837arg0: Flag8,838) -> wasmtime::Result<Flag8>839where840<S as wasmtime::AsContext>::Data: Send,841{842let callee = unsafe {843wasmtime::component::TypedFunc::<844(Flag8,),845(Flag8,),846>::new_unchecked(self.roundtrip_flag8)847};848let (ret0,) = callee849.call_async(store.as_context_mut(), (arg0,))850.await?;851Ok(ret0)852}853pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(854&self,855mut store: S,856arg0: Flag16,857) -> wasmtime::Result<Flag16>858where859<S as wasmtime::AsContext>::Data: Send,860{861let callee = unsafe {862wasmtime::component::TypedFunc::<863(Flag16,),864(Flag16,),865>::new_unchecked(self.roundtrip_flag16)866};867let (ret0,) = callee868.call_async(store.as_context_mut(), (arg0,))869.await?;870Ok(ret0)871}872pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(873&self,874mut store: S,875arg0: Flag32,876) -> wasmtime::Result<Flag32>877where878<S as wasmtime::AsContext>::Data: Send,879{880let callee = unsafe {881wasmtime::component::TypedFunc::<882(Flag32,),883(Flag32,),884>::new_unchecked(self.roundtrip_flag32)885};886let (ret0,) = callee887.call_async(store.as_context_mut(), (arg0,))888.await?;889Ok(ret0)890}891pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(892&self,893mut store: S,894arg0: Flag64,895) -> wasmtime::Result<Flag64>896where897<S as wasmtime::AsContext>::Data: Send,898{899let callee = unsafe {900wasmtime::component::TypedFunc::<901(Flag64,),902(Flag64,),903>::new_unchecked(self.roundtrip_flag64)904};905let (ret0,) = callee906.call_async(store.as_context_mut(), (arg0,))907.await?;908Ok(ret0)909}910}911}912}913}914}915916917