Path: blob/main/crates/component-macro/tests/expanded/flags.rs
3069 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,174for<'a> D::Data<'a>: foo::foo::flegs::Host,175T: 'static,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 {}306impl<_T: ?Sized> HostWithStore for _T307where308_T: wasmtime::component::HasData,309{}310pub trait Host {311fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1;312fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2;313fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4;314fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8;315fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16;316fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32;317fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64;318}319impl<_T: Host + ?Sized> Host for &mut _T {320fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1 {321Host::roundtrip_flag1(*self, x)322}323fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2 {324Host::roundtrip_flag2(*self, x)325}326fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4 {327Host::roundtrip_flag4(*self, x)328}329fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8 {330Host::roundtrip_flag8(*self, x)331}332fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16 {333Host::roundtrip_flag16(*self, x)334}335fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32 {336Host::roundtrip_flag32(*self, x)337}338fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64 {339Host::roundtrip_flag64(*self, x)340}341}342pub fn add_to_linker<T, D>(343linker: &mut wasmtime::component::Linker<T>,344host_getter: fn(&mut T) -> D::Data<'_>,345) -> wasmtime::Result<()>346where347D: HostWithStore,348for<'a> D::Data<'a>: Host,349T: 'static,350{351let mut inst = linker.instance("foo:foo/flegs")?;352inst.func_wrap(353"roundtrip-flag1",354move |355mut caller: wasmtime::StoreContextMut<'_, T>,356(arg0,): (Flag1,)|357{358let host = &mut host_getter(caller.data_mut());359let r = Host::roundtrip_flag1(host, arg0);360Ok((r,))361},362)?;363inst.func_wrap(364"roundtrip-flag2",365move |366mut caller: wasmtime::StoreContextMut<'_, T>,367(arg0,): (Flag2,)|368{369let host = &mut host_getter(caller.data_mut());370let r = Host::roundtrip_flag2(host, arg0);371Ok((r,))372},373)?;374inst.func_wrap(375"roundtrip-flag4",376move |377mut caller: wasmtime::StoreContextMut<'_, T>,378(arg0,): (Flag4,)|379{380let host = &mut host_getter(caller.data_mut());381let r = Host::roundtrip_flag4(host, arg0);382Ok((r,))383},384)?;385inst.func_wrap(386"roundtrip-flag8",387move |388mut caller: wasmtime::StoreContextMut<'_, T>,389(arg0,): (Flag8,)|390{391let host = &mut host_getter(caller.data_mut());392let r = Host::roundtrip_flag8(host, arg0);393Ok((r,))394},395)?;396inst.func_wrap(397"roundtrip-flag16",398move |399mut caller: wasmtime::StoreContextMut<'_, T>,400(arg0,): (Flag16,)|401{402let host = &mut host_getter(caller.data_mut());403let r = Host::roundtrip_flag16(host, arg0);404Ok((r,))405},406)?;407inst.func_wrap(408"roundtrip-flag32",409move |410mut caller: wasmtime::StoreContextMut<'_, T>,411(arg0,): (Flag32,)|412{413let host = &mut host_getter(caller.data_mut());414let r = Host::roundtrip_flag32(host, arg0);415Ok((r,))416},417)?;418inst.func_wrap(419"roundtrip-flag64",420move |421mut caller: wasmtime::StoreContextMut<'_, T>,422(arg0,): (Flag64,)|423{424let host = &mut host_getter(caller.data_mut());425let r = Host::roundtrip_flag64(host, arg0);426Ok((r,))427},428)?;429Ok(())430}431}432}433}434pub mod exports {435pub mod foo {436pub mod foo {437#[allow(clippy::all)]438pub mod flegs {439#[allow(unused_imports)]440use wasmtime::component::__internal::Box;441wasmtime::component::flags!(442Flag1 { #[component(name = "b0")] const B0; }443);444const _: () = {445assert!(4461 == < Flag1 as wasmtime::component::ComponentType >::SIZE32447);448assert!(4491 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32450);451};452wasmtime::component::flags!(453Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]454const B1; }455);456const _: () = {457assert!(4581 == < Flag2 as wasmtime::component::ComponentType >::SIZE32459);460assert!(4611 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32462);463};464wasmtime::component::flags!(465Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]466const B1; #[component(name = "b2")] const B2; #[component(name =467"b3")] const B3; }468);469const _: () = {470assert!(4711 == < Flag4 as wasmtime::component::ComponentType >::SIZE32472);473assert!(4741 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32475);476};477wasmtime::component::flags!(478Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]479const B1; #[component(name = "b2")] const B2; #[component(name =480"b3")] const B3; #[component(name = "b4")] const B4; #[component(name481= "b5")] const B5; #[component(name = "b6")] const B6;482#[component(name = "b7")] const B7; }483);484const _: () = {485assert!(4861 == < Flag8 as wasmtime::component::ComponentType >::SIZE32487);488assert!(4891 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32490);491};492wasmtime::component::flags!(493Flag16 { #[component(name = "b0")] const B0; #[component(name =494"b1")] const B1; #[component(name = "b2")] const B2; #[component(name495= "b3")] const B3; #[component(name = "b4")] const B4;496#[component(name = "b5")] const B5; #[component(name = "b6")] const497B6; #[component(name = "b7")] const B7; #[component(name = "b8")]498const B8; #[component(name = "b9")] const B9; #[component(name =499"b10")] const B10; #[component(name = "b11")] const B11;500#[component(name = "b12")] const B12; #[component(name = "b13")]501const B13; #[component(name = "b14")] const B14; #[component(name =502"b15")] const B15; }503);504const _: () = {505assert!(5062 == < Flag16 as wasmtime::component::ComponentType >::SIZE32507);508assert!(5092 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32510);511};512wasmtime::component::flags!(513Flag32 { #[component(name = "b0")] const B0; #[component(name =514"b1")] const B1; #[component(name = "b2")] const B2; #[component(name515= "b3")] const B3; #[component(name = "b4")] const B4;516#[component(name = "b5")] const B5; #[component(name = "b6")] const517B6; #[component(name = "b7")] const B7; #[component(name = "b8")]518const B8; #[component(name = "b9")] const B9; #[component(name =519"b10")] const B10; #[component(name = "b11")] const B11;520#[component(name = "b12")] const B12; #[component(name = "b13")]521const B13; #[component(name = "b14")] const B14; #[component(name =522"b15")] const B15; #[component(name = "b16")] const B16;523#[component(name = "b17")] const B17; #[component(name = "b18")]524const B18; #[component(name = "b19")] const B19; #[component(name =525"b20")] const B20; #[component(name = "b21")] const B21;526#[component(name = "b22")] const B22; #[component(name = "b23")]527const B23; #[component(name = "b24")] const B24; #[component(name =528"b25")] const B25; #[component(name = "b26")] const B26;529#[component(name = "b27")] const B27; #[component(name = "b28")]530const B28; #[component(name = "b29")] const B29; #[component(name =531"b30")] const B30; #[component(name = "b31")] const B31; }532);533const _: () = {534assert!(5354 == < Flag32 as wasmtime::component::ComponentType >::SIZE32536);537assert!(5384 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32539);540};541wasmtime::component::flags!(542Flag64 { #[component(name = "b0")] const B0; #[component(name =543"b1")] const B1; #[component(name = "b2")] const B2; #[component(name544= "b3")] const B3; #[component(name = "b4")] const B4;545#[component(name = "b5")] const B5; #[component(name = "b6")] const546B6; #[component(name = "b7")] const B7; #[component(name = "b8")]547const B8; #[component(name = "b9")] const B9; #[component(name =548"b10")] const B10; #[component(name = "b11")] const B11;549#[component(name = "b12")] const B12; #[component(name = "b13")]550const B13; #[component(name = "b14")] const B14; #[component(name =551"b15")] const B15; #[component(name = "b16")] const B16;552#[component(name = "b17")] const B17; #[component(name = "b18")]553const B18; #[component(name = "b19")] const B19; #[component(name =554"b20")] const B20; #[component(name = "b21")] const B21;555#[component(name = "b22")] const B22; #[component(name = "b23")]556const B23; #[component(name = "b24")] const B24; #[component(name =557"b25")] const B25; #[component(name = "b26")] const B26;558#[component(name = "b27")] const B27; #[component(name = "b28")]559const B28; #[component(name = "b29")] const B29; #[component(name =560"b30")] const B30; #[component(name = "b31")] const B31;561#[component(name = "b32")] const B32; #[component(name = "b33")]562const B33; #[component(name = "b34")] const B34; #[component(name =563"b35")] const B35; #[component(name = "b36")] const B36;564#[component(name = "b37")] const B37; #[component(name = "b38")]565const B38; #[component(name = "b39")] const B39; #[component(name =566"b40")] const B40; #[component(name = "b41")] const B41;567#[component(name = "b42")] const B42; #[component(name = "b43")]568const B43; #[component(name = "b44")] const B44; #[component(name =569"b45")] const B45; #[component(name = "b46")] const B46;570#[component(name = "b47")] const B47; #[component(name = "b48")]571const B48; #[component(name = "b49")] const B49; #[component(name =572"b50")] const B50; #[component(name = "b51")] const B51;573#[component(name = "b52")] const B52; #[component(name = "b53")]574const B53; #[component(name = "b54")] const B54; #[component(name =575"b55")] const B55; #[component(name = "b56")] const B56;576#[component(name = "b57")] const B57; #[component(name = "b58")]577const B58; #[component(name = "b59")] const B59; #[component(name =578"b60")] const B60; #[component(name = "b61")] const B61;579#[component(name = "b62")] const B62; #[component(name = "b63")]580const B63; }581);582const _: () = {583assert!(5848 == < Flag64 as wasmtime::component::ComponentType >::SIZE32585);586assert!(5874 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32588);589};590#[derive(Clone)]591pub struct Guest {592roundtrip_flag1: wasmtime::component::Func,593roundtrip_flag2: wasmtime::component::Func,594roundtrip_flag4: wasmtime::component::Func,595roundtrip_flag8: wasmtime::component::Func,596roundtrip_flag16: wasmtime::component::Func,597roundtrip_flag32: wasmtime::component::Func,598roundtrip_flag64: wasmtime::component::Func,599}600#[derive(Clone)]601pub struct GuestIndices {602roundtrip_flag1: wasmtime::component::ComponentExportIndex,603roundtrip_flag2: wasmtime::component::ComponentExportIndex,604roundtrip_flag4: wasmtime::component::ComponentExportIndex,605roundtrip_flag8: wasmtime::component::ComponentExportIndex,606roundtrip_flag16: wasmtime::component::ComponentExportIndex,607roundtrip_flag32: wasmtime::component::ComponentExportIndex,608roundtrip_flag64: wasmtime::component::ComponentExportIndex,609}610impl GuestIndices {611/// Constructor for [`GuestIndices`] which takes a612/// [`Component`](wasmtime::component::Component) as input and can be executed613/// before instantiation.614///615/// This constructor can be used to front-load string lookups to find exports616/// within a component.617pub fn new<_T>(618_instance_pre: &wasmtime::component::InstancePre<_T>,619) -> wasmtime::Result<GuestIndices> {620let instance = _instance_pre621.component()622.get_export_index(None, "foo:foo/flegs")623.ok_or_else(|| {624wasmtime::format_err!(625"no exported instance named `foo:foo/flegs`"626)627})?;628let mut lookup = move |name| {629_instance_pre630.component()631.get_export_index(Some(&instance), name)632.ok_or_else(|| {633wasmtime::format_err!(634"instance export `foo:foo/flegs` does \635not have export `{name}`"636)637})638};639let _ = &mut lookup;640let roundtrip_flag1 = lookup("roundtrip-flag1")?;641let roundtrip_flag2 = lookup("roundtrip-flag2")?;642let roundtrip_flag4 = lookup("roundtrip-flag4")?;643let roundtrip_flag8 = lookup("roundtrip-flag8")?;644let roundtrip_flag16 = lookup("roundtrip-flag16")?;645let roundtrip_flag32 = lookup("roundtrip-flag32")?;646let roundtrip_flag64 = lookup("roundtrip-flag64")?;647Ok(GuestIndices {648roundtrip_flag1,649roundtrip_flag2,650roundtrip_flag4,651roundtrip_flag8,652roundtrip_flag16,653roundtrip_flag32,654roundtrip_flag64,655})656}657pub fn load(658&self,659mut store: impl wasmtime::AsContextMut,660instance: &wasmtime::component::Instance,661) -> wasmtime::Result<Guest> {662let _instance = instance;663let _instance_pre = _instance.instance_pre(&store);664let _instance_type = _instance_pre.instance_type();665let mut store = store.as_context_mut();666let _ = &mut store;667let roundtrip_flag1 = *_instance668.get_typed_func::<669(Flag1,),670(Flag1,),671>(&mut store, &self.roundtrip_flag1)?672.func();673let roundtrip_flag2 = *_instance674.get_typed_func::<675(Flag2,),676(Flag2,),677>(&mut store, &self.roundtrip_flag2)?678.func();679let roundtrip_flag4 = *_instance680.get_typed_func::<681(Flag4,),682(Flag4,),683>(&mut store, &self.roundtrip_flag4)?684.func();685let roundtrip_flag8 = *_instance686.get_typed_func::<687(Flag8,),688(Flag8,),689>(&mut store, &self.roundtrip_flag8)?690.func();691let roundtrip_flag16 = *_instance692.get_typed_func::<693(Flag16,),694(Flag16,),695>(&mut store, &self.roundtrip_flag16)?696.func();697let roundtrip_flag32 = *_instance698.get_typed_func::<699(Flag32,),700(Flag32,),701>(&mut store, &self.roundtrip_flag32)?702.func();703let roundtrip_flag64 = *_instance704.get_typed_func::<705(Flag64,),706(Flag64,),707>(&mut store, &self.roundtrip_flag64)?708.func();709Ok(Guest {710roundtrip_flag1,711roundtrip_flag2,712roundtrip_flag4,713roundtrip_flag8,714roundtrip_flag16,715roundtrip_flag32,716roundtrip_flag64,717})718}719}720impl Guest {721pub fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(722&self,723mut store: S,724arg0: Flag1,725) -> wasmtime::Result<Flag1> {726let callee = unsafe {727wasmtime::component::TypedFunc::<728(Flag1,),729(Flag1,),730>::new_unchecked(self.roundtrip_flag1)731};732let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;733Ok(ret0)734}735pub fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(736&self,737mut store: S,738arg0: Flag2,739) -> wasmtime::Result<Flag2> {740let callee = unsafe {741wasmtime::component::TypedFunc::<742(Flag2,),743(Flag2,),744>::new_unchecked(self.roundtrip_flag2)745};746let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;747Ok(ret0)748}749pub fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(750&self,751mut store: S,752arg0: Flag4,753) -> wasmtime::Result<Flag4> {754let callee = unsafe {755wasmtime::component::TypedFunc::<756(Flag4,),757(Flag4,),758>::new_unchecked(self.roundtrip_flag4)759};760let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;761Ok(ret0)762}763pub fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(764&self,765mut store: S,766arg0: Flag8,767) -> wasmtime::Result<Flag8> {768let callee = unsafe {769wasmtime::component::TypedFunc::<770(Flag8,),771(Flag8,),772>::new_unchecked(self.roundtrip_flag8)773};774let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;775Ok(ret0)776}777pub fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(778&self,779mut store: S,780arg0: Flag16,781) -> wasmtime::Result<Flag16> {782let callee = unsafe {783wasmtime::component::TypedFunc::<784(Flag16,),785(Flag16,),786>::new_unchecked(self.roundtrip_flag16)787};788let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;789Ok(ret0)790}791pub fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(792&self,793mut store: S,794arg0: Flag32,795) -> wasmtime::Result<Flag32> {796let callee = unsafe {797wasmtime::component::TypedFunc::<798(Flag32,),799(Flag32,),800>::new_unchecked(self.roundtrip_flag32)801};802let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;803Ok(ret0)804}805pub fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(806&self,807mut store: S,808arg0: Flag64,809) -> wasmtime::Result<Flag64> {810let callee = unsafe {811wasmtime::component::TypedFunc::<812(Flag64,),813(Flag64,),814>::new_unchecked(self.roundtrip_flag64)815};816let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;817Ok(ret0)818}819}820}821}822}823}824825826