Path: blob/main/crates/component-macro/tests/expanded/flags_concurrent.rs
3072 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 {306fn roundtrip_flag1<T: Send>(307accessor: &wasmtime::component::Accessor<T, Self>,308x: Flag1,309) -> impl ::core::future::Future<Output = Flag1> + Send;310fn roundtrip_flag2<T: Send>(311accessor: &wasmtime::component::Accessor<T, Self>,312x: Flag2,313) -> impl ::core::future::Future<Output = Flag2> + Send;314fn roundtrip_flag4<T: Send>(315accessor: &wasmtime::component::Accessor<T, Self>,316x: Flag4,317) -> impl ::core::future::Future<Output = Flag4> + Send;318fn roundtrip_flag8<T: Send>(319accessor: &wasmtime::component::Accessor<T, Self>,320x: Flag8,321) -> impl ::core::future::Future<Output = Flag8> + Send;322fn roundtrip_flag16<T: Send>(323accessor: &wasmtime::component::Accessor<T, Self>,324x: Flag16,325) -> impl ::core::future::Future<Output = Flag16> + Send;326fn roundtrip_flag32<T: Send>(327accessor: &wasmtime::component::Accessor<T, Self>,328x: Flag32,329) -> impl ::core::future::Future<Output = Flag32> + Send;330fn roundtrip_flag64<T: Send>(331accessor: &wasmtime::component::Accessor<T, Self>,332x: Flag64,333) -> impl ::core::future::Future<Output = Flag64> + Send;334}335pub trait Host: Send {}336impl<_T: Host + ?Sized + Send> Host for &mut _T {}337pub fn add_to_linker<T, D>(338linker: &mut wasmtime::component::Linker<T>,339host_getter: fn(&mut T) -> D::Data<'_>,340) -> wasmtime::Result<()>341where342D: HostWithStore,343for<'a> D::Data<'a>: Host,344T: 'static + Send,345{346let mut inst = linker.instance("foo:foo/flegs")?;347inst.func_wrap_concurrent(348"roundtrip-flag1",349move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag1,)| {350wasmtime::component::__internal::Box::pin(async move {351let host = &caller.with_getter(host_getter);352let r = <D as HostWithStore>::roundtrip_flag1(host, arg0)353.await;354Ok((r,))355})356},357)?;358inst.func_wrap_concurrent(359"roundtrip-flag2",360move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag2,)| {361wasmtime::component::__internal::Box::pin(async move {362let host = &caller.with_getter(host_getter);363let r = <D as HostWithStore>::roundtrip_flag2(host, arg0)364.await;365Ok((r,))366})367},368)?;369inst.func_wrap_concurrent(370"roundtrip-flag4",371move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag4,)| {372wasmtime::component::__internal::Box::pin(async move {373let host = &caller.with_getter(host_getter);374let r = <D as HostWithStore>::roundtrip_flag4(host, arg0)375.await;376Ok((r,))377})378},379)?;380inst.func_wrap_concurrent(381"roundtrip-flag8",382move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag8,)| {383wasmtime::component::__internal::Box::pin(async move {384let host = &caller.with_getter(host_getter);385let r = <D as HostWithStore>::roundtrip_flag8(host, arg0)386.await;387Ok((r,))388})389},390)?;391inst.func_wrap_concurrent(392"roundtrip-flag16",393move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag16,)| {394wasmtime::component::__internal::Box::pin(async move {395let host = &caller.with_getter(host_getter);396let r = <D as HostWithStore>::roundtrip_flag16(host, arg0)397.await;398Ok((r,))399})400},401)?;402inst.func_wrap_concurrent(403"roundtrip-flag32",404move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag32,)| {405wasmtime::component::__internal::Box::pin(async move {406let host = &caller.with_getter(host_getter);407let r = <D as HostWithStore>::roundtrip_flag32(host, arg0)408.await;409Ok((r,))410})411},412)?;413inst.func_wrap_concurrent(414"roundtrip-flag64",415move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag64,)| {416wasmtime::component::__internal::Box::pin(async move {417let host = &caller.with_getter(host_getter);418let r = <D as HostWithStore>::roundtrip_flag64(host, arg0)419.await;420Ok((r,))421})422},423)?;424Ok(())425}426}427}428}429pub mod exports {430pub mod foo {431pub mod foo {432#[allow(clippy::all)]433pub mod flegs {434#[allow(unused_imports)]435use wasmtime::component::__internal::Box;436wasmtime::component::flags!(437Flag1 { #[component(name = "b0")] const B0; }438);439const _: () = {440assert!(4411 == < Flag1 as wasmtime::component::ComponentType >::SIZE32442);443assert!(4441 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32445);446};447wasmtime::component::flags!(448Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]449const B1; }450);451const _: () = {452assert!(4531 == < Flag2 as wasmtime::component::ComponentType >::SIZE32454);455assert!(4561 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32457);458};459wasmtime::component::flags!(460Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]461const B1; #[component(name = "b2")] const B2; #[component(name =462"b3")] const B3; }463);464const _: () = {465assert!(4661 == < Flag4 as wasmtime::component::ComponentType >::SIZE32467);468assert!(4691 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32470);471};472wasmtime::component::flags!(473Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]474const B1; #[component(name = "b2")] const B2; #[component(name =475"b3")] const B3; #[component(name = "b4")] const B4; #[component(name476= "b5")] const B5; #[component(name = "b6")] const B6;477#[component(name = "b7")] const B7; }478);479const _: () = {480assert!(4811 == < Flag8 as wasmtime::component::ComponentType >::SIZE32482);483assert!(4841 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32485);486};487wasmtime::component::flags!(488Flag16 { #[component(name = "b0")] const B0; #[component(name =489"b1")] const B1; #[component(name = "b2")] const B2; #[component(name490= "b3")] const B3; #[component(name = "b4")] const B4;491#[component(name = "b5")] const B5; #[component(name = "b6")] const492B6; #[component(name = "b7")] const B7; #[component(name = "b8")]493const B8; #[component(name = "b9")] const B9; #[component(name =494"b10")] const B10; #[component(name = "b11")] const B11;495#[component(name = "b12")] const B12; #[component(name = "b13")]496const B13; #[component(name = "b14")] const B14; #[component(name =497"b15")] const B15; }498);499const _: () = {500assert!(5012 == < Flag16 as wasmtime::component::ComponentType >::SIZE32502);503assert!(5042 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32505);506};507wasmtime::component::flags!(508Flag32 { #[component(name = "b0")] const B0; #[component(name =509"b1")] const B1; #[component(name = "b2")] const B2; #[component(name510= "b3")] const B3; #[component(name = "b4")] const B4;511#[component(name = "b5")] const B5; #[component(name = "b6")] const512B6; #[component(name = "b7")] const B7; #[component(name = "b8")]513const B8; #[component(name = "b9")] const B9; #[component(name =514"b10")] const B10; #[component(name = "b11")] const B11;515#[component(name = "b12")] const B12; #[component(name = "b13")]516const B13; #[component(name = "b14")] const B14; #[component(name =517"b15")] const B15; #[component(name = "b16")] const B16;518#[component(name = "b17")] const B17; #[component(name = "b18")]519const B18; #[component(name = "b19")] const B19; #[component(name =520"b20")] const B20; #[component(name = "b21")] const B21;521#[component(name = "b22")] const B22; #[component(name = "b23")]522const B23; #[component(name = "b24")] const B24; #[component(name =523"b25")] const B25; #[component(name = "b26")] const B26;524#[component(name = "b27")] const B27; #[component(name = "b28")]525const B28; #[component(name = "b29")] const B29; #[component(name =526"b30")] const B30; #[component(name = "b31")] const B31; }527);528const _: () = {529assert!(5304 == < Flag32 as wasmtime::component::ComponentType >::SIZE32531);532assert!(5334 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32534);535};536wasmtime::component::flags!(537Flag64 { #[component(name = "b0")] const B0; #[component(name =538"b1")] const B1; #[component(name = "b2")] const B2; #[component(name539= "b3")] const B3; #[component(name = "b4")] const B4;540#[component(name = "b5")] const B5; #[component(name = "b6")] const541B6; #[component(name = "b7")] const B7; #[component(name = "b8")]542const B8; #[component(name = "b9")] const B9; #[component(name =543"b10")] const B10; #[component(name = "b11")] const B11;544#[component(name = "b12")] const B12; #[component(name = "b13")]545const B13; #[component(name = "b14")] const B14; #[component(name =546"b15")] const B15; #[component(name = "b16")] const B16;547#[component(name = "b17")] const B17; #[component(name = "b18")]548const B18; #[component(name = "b19")] const B19; #[component(name =549"b20")] const B20; #[component(name = "b21")] const B21;550#[component(name = "b22")] const B22; #[component(name = "b23")]551const B23; #[component(name = "b24")] const B24; #[component(name =552"b25")] const B25; #[component(name = "b26")] const B26;553#[component(name = "b27")] const B27; #[component(name = "b28")]554const B28; #[component(name = "b29")] const B29; #[component(name =555"b30")] const B30; #[component(name = "b31")] const B31;556#[component(name = "b32")] const B32; #[component(name = "b33")]557const B33; #[component(name = "b34")] const B34; #[component(name =558"b35")] const B35; #[component(name = "b36")] const B36;559#[component(name = "b37")] const B37; #[component(name = "b38")]560const B38; #[component(name = "b39")] const B39; #[component(name =561"b40")] const B40; #[component(name = "b41")] const B41;562#[component(name = "b42")] const B42; #[component(name = "b43")]563const B43; #[component(name = "b44")] const B44; #[component(name =564"b45")] const B45; #[component(name = "b46")] const B46;565#[component(name = "b47")] const B47; #[component(name = "b48")]566const B48; #[component(name = "b49")] const B49; #[component(name =567"b50")] const B50; #[component(name = "b51")] const B51;568#[component(name = "b52")] const B52; #[component(name = "b53")]569const B53; #[component(name = "b54")] const B54; #[component(name =570"b55")] const B55; #[component(name = "b56")] const B56;571#[component(name = "b57")] const B57; #[component(name = "b58")]572const B58; #[component(name = "b59")] const B59; #[component(name =573"b60")] const B60; #[component(name = "b61")] const B61;574#[component(name = "b62")] const B62; #[component(name = "b63")]575const B63; }576);577const _: () = {578assert!(5798 == < Flag64 as wasmtime::component::ComponentType >::SIZE32580);581assert!(5824 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32583);584};585#[derive(Clone)]586pub struct Guest {587roundtrip_flag1: wasmtime::component::Func,588roundtrip_flag2: wasmtime::component::Func,589roundtrip_flag4: wasmtime::component::Func,590roundtrip_flag8: wasmtime::component::Func,591roundtrip_flag16: wasmtime::component::Func,592roundtrip_flag32: wasmtime::component::Func,593roundtrip_flag64: wasmtime::component::Func,594}595#[derive(Clone)]596pub struct GuestIndices {597roundtrip_flag1: wasmtime::component::ComponentExportIndex,598roundtrip_flag2: wasmtime::component::ComponentExportIndex,599roundtrip_flag4: wasmtime::component::ComponentExportIndex,600roundtrip_flag8: wasmtime::component::ComponentExportIndex,601roundtrip_flag16: wasmtime::component::ComponentExportIndex,602roundtrip_flag32: wasmtime::component::ComponentExportIndex,603roundtrip_flag64: wasmtime::component::ComponentExportIndex,604}605impl GuestIndices {606/// Constructor for [`GuestIndices`] which takes a607/// [`Component`](wasmtime::component::Component) as input and can be executed608/// before instantiation.609///610/// This constructor can be used to front-load string lookups to find exports611/// within a component.612pub fn new<_T>(613_instance_pre: &wasmtime::component::InstancePre<_T>,614) -> wasmtime::Result<GuestIndices> {615let instance = _instance_pre616.component()617.get_export_index(None, "foo:foo/flegs")618.ok_or_else(|| {619wasmtime::format_err!(620"no exported instance named `foo:foo/flegs`"621)622})?;623let mut lookup = move |name| {624_instance_pre625.component()626.get_export_index(Some(&instance), name)627.ok_or_else(|| {628wasmtime::format_err!(629"instance export `foo:foo/flegs` does \630not have export `{name}`"631)632})633};634let _ = &mut lookup;635let roundtrip_flag1 = lookup("roundtrip-flag1")?;636let roundtrip_flag2 = lookup("roundtrip-flag2")?;637let roundtrip_flag4 = lookup("roundtrip-flag4")?;638let roundtrip_flag8 = lookup("roundtrip-flag8")?;639let roundtrip_flag16 = lookup("roundtrip-flag16")?;640let roundtrip_flag32 = lookup("roundtrip-flag32")?;641let roundtrip_flag64 = lookup("roundtrip-flag64")?;642Ok(GuestIndices {643roundtrip_flag1,644roundtrip_flag2,645roundtrip_flag4,646roundtrip_flag8,647roundtrip_flag16,648roundtrip_flag32,649roundtrip_flag64,650})651}652pub fn load(653&self,654mut store: impl wasmtime::AsContextMut,655instance: &wasmtime::component::Instance,656) -> wasmtime::Result<Guest> {657let _instance = instance;658let _instance_pre = _instance.instance_pre(&store);659let _instance_type = _instance_pre.instance_type();660let mut store = store.as_context_mut();661let _ = &mut store;662let roundtrip_flag1 = *_instance663.get_typed_func::<664(Flag1,),665(Flag1,),666>(&mut store, &self.roundtrip_flag1)?667.func();668let roundtrip_flag2 = *_instance669.get_typed_func::<670(Flag2,),671(Flag2,),672>(&mut store, &self.roundtrip_flag2)?673.func();674let roundtrip_flag4 = *_instance675.get_typed_func::<676(Flag4,),677(Flag4,),678>(&mut store, &self.roundtrip_flag4)?679.func();680let roundtrip_flag8 = *_instance681.get_typed_func::<682(Flag8,),683(Flag8,),684>(&mut store, &self.roundtrip_flag8)?685.func();686let roundtrip_flag16 = *_instance687.get_typed_func::<688(Flag16,),689(Flag16,),690>(&mut store, &self.roundtrip_flag16)?691.func();692let roundtrip_flag32 = *_instance693.get_typed_func::<694(Flag32,),695(Flag32,),696>(&mut store, &self.roundtrip_flag32)?697.func();698let roundtrip_flag64 = *_instance699.get_typed_func::<700(Flag64,),701(Flag64,),702>(&mut store, &self.roundtrip_flag64)?703.func();704Ok(Guest {705roundtrip_flag1,706roundtrip_flag2,707roundtrip_flag4,708roundtrip_flag8,709roundtrip_flag16,710roundtrip_flag32,711roundtrip_flag64,712})713}714}715impl Guest {716pub async fn call_roundtrip_flag1<_T, _D>(717&self,718accessor: &wasmtime::component::Accessor<_T, _D>,719arg0: Flag1,720) -> wasmtime::Result<Flag1>721where722_T: Send,723_D: wasmtime::component::HasData,724{725let callee = unsafe {726wasmtime::component::TypedFunc::<727(Flag1,),728(Flag1,),729>::new_unchecked(self.roundtrip_flag1)730};731let ((ret0,), _) = callee732.call_concurrent(accessor, (arg0,))733.await?;734Ok(ret0)735}736pub async fn call_roundtrip_flag2<_T, _D>(737&self,738accessor: &wasmtime::component::Accessor<_T, _D>,739arg0: Flag2,740) -> wasmtime::Result<Flag2>741where742_T: Send,743_D: wasmtime::component::HasData,744{745let callee = unsafe {746wasmtime::component::TypedFunc::<747(Flag2,),748(Flag2,),749>::new_unchecked(self.roundtrip_flag2)750};751let ((ret0,), _) = callee752.call_concurrent(accessor, (arg0,))753.await?;754Ok(ret0)755}756pub async fn call_roundtrip_flag4<_T, _D>(757&self,758accessor: &wasmtime::component::Accessor<_T, _D>,759arg0: Flag4,760) -> wasmtime::Result<Flag4>761where762_T: Send,763_D: wasmtime::component::HasData,764{765let callee = unsafe {766wasmtime::component::TypedFunc::<767(Flag4,),768(Flag4,),769>::new_unchecked(self.roundtrip_flag4)770};771let ((ret0,), _) = callee772.call_concurrent(accessor, (arg0,))773.await?;774Ok(ret0)775}776pub async fn call_roundtrip_flag8<_T, _D>(777&self,778accessor: &wasmtime::component::Accessor<_T, _D>,779arg0: Flag8,780) -> wasmtime::Result<Flag8>781where782_T: Send,783_D: wasmtime::component::HasData,784{785let callee = unsafe {786wasmtime::component::TypedFunc::<787(Flag8,),788(Flag8,),789>::new_unchecked(self.roundtrip_flag8)790};791let ((ret0,), _) = callee792.call_concurrent(accessor, (arg0,))793.await?;794Ok(ret0)795}796pub async fn call_roundtrip_flag16<_T, _D>(797&self,798accessor: &wasmtime::component::Accessor<_T, _D>,799arg0: Flag16,800) -> wasmtime::Result<Flag16>801where802_T: Send,803_D: wasmtime::component::HasData,804{805let callee = unsafe {806wasmtime::component::TypedFunc::<807(Flag16,),808(Flag16,),809>::new_unchecked(self.roundtrip_flag16)810};811let ((ret0,), _) = callee812.call_concurrent(accessor, (arg0,))813.await?;814Ok(ret0)815}816pub async fn call_roundtrip_flag32<_T, _D>(817&self,818accessor: &wasmtime::component::Accessor<_T, _D>,819arg0: Flag32,820) -> wasmtime::Result<Flag32>821where822_T: Send,823_D: wasmtime::component::HasData,824{825let callee = unsafe {826wasmtime::component::TypedFunc::<827(Flag32,),828(Flag32,),829>::new_unchecked(self.roundtrip_flag32)830};831let ((ret0,), _) = callee832.call_concurrent(accessor, (arg0,))833.await?;834Ok(ret0)835}836pub async fn call_roundtrip_flag64<_T, _D>(837&self,838accessor: &wasmtime::component::Accessor<_T, _D>,839arg0: Flag64,840) -> wasmtime::Result<Flag64>841where842_T: Send,843_D: wasmtime::component::HasData,844{845let callee = unsafe {846wasmtime::component::TypedFunc::<847(Flag64,),848(Flag64,),849>::new_unchecked(self.roundtrip_flag64)850};851let ((ret0,), _) = callee852.call_concurrent(accessor, (arg0,))853.await?;854Ok(ret0)855}856}857}858}859}860}861862863