Path: blob/main/crates/component-macro/tests/expanded/flags.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,176for<'a> D::Data<'a>: foo::foo::flegs::Host,177T: 'static,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 {}308impl<_T: ?Sized> HostWithStore for _T309where310_T: wasmtime::component::HasData,311{}312pub trait Host {313fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1;314fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2;315fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4;316fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8;317fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16;318fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32;319fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64;320}321impl<_T: Host + ?Sized> Host for &mut _T {322fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1 {323Host::roundtrip_flag1(*self, x)324}325fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2 {326Host::roundtrip_flag2(*self, x)327}328fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4 {329Host::roundtrip_flag4(*self, x)330}331fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8 {332Host::roundtrip_flag8(*self, x)333}334fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16 {335Host::roundtrip_flag16(*self, x)336}337fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32 {338Host::roundtrip_flag32(*self, x)339}340fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64 {341Host::roundtrip_flag64(*self, x)342}343}344pub fn add_to_linker<T, D>(345linker: &mut wasmtime::component::Linker<T>,346host_getter: fn(&mut T) -> D::Data<'_>,347) -> wasmtime::Result<()>348where349D: HostWithStore,350for<'a> D::Data<'a>: Host,351T: 'static,352{353let mut inst = linker.instance("foo:foo/flegs")?;354inst.func_wrap(355"roundtrip-flag1",356move |357mut caller: wasmtime::StoreContextMut<'_, T>,358(arg0,): (Flag1,)|359{360let host = &mut host_getter(caller.data_mut());361let r = Host::roundtrip_flag1(host, arg0);362Ok((r,))363},364)?;365inst.func_wrap(366"roundtrip-flag2",367move |368mut caller: wasmtime::StoreContextMut<'_, T>,369(arg0,): (Flag2,)|370{371let host = &mut host_getter(caller.data_mut());372let r = Host::roundtrip_flag2(host, arg0);373Ok((r,))374},375)?;376inst.func_wrap(377"roundtrip-flag4",378move |379mut caller: wasmtime::StoreContextMut<'_, T>,380(arg0,): (Flag4,)|381{382let host = &mut host_getter(caller.data_mut());383let r = Host::roundtrip_flag4(host, arg0);384Ok((r,))385},386)?;387inst.func_wrap(388"roundtrip-flag8",389move |390mut caller: wasmtime::StoreContextMut<'_, T>,391(arg0,): (Flag8,)|392{393let host = &mut host_getter(caller.data_mut());394let r = Host::roundtrip_flag8(host, arg0);395Ok((r,))396},397)?;398inst.func_wrap(399"roundtrip-flag16",400move |401mut caller: wasmtime::StoreContextMut<'_, T>,402(arg0,): (Flag16,)|403{404let host = &mut host_getter(caller.data_mut());405let r = Host::roundtrip_flag16(host, arg0);406Ok((r,))407},408)?;409inst.func_wrap(410"roundtrip-flag32",411move |412mut caller: wasmtime::StoreContextMut<'_, T>,413(arg0,): (Flag32,)|414{415let host = &mut host_getter(caller.data_mut());416let r = Host::roundtrip_flag32(host, arg0);417Ok((r,))418},419)?;420inst.func_wrap(421"roundtrip-flag64",422move |423mut caller: wasmtime::StoreContextMut<'_, T>,424(arg0,): (Flag64,)|425{426let host = &mut host_getter(caller.data_mut());427let r = Host::roundtrip_flag64(host, arg0);428Ok((r,))429},430)?;431Ok(())432}433}434}435}436pub mod exports {437pub mod foo {438pub mod foo {439#[allow(clippy::all)]440pub mod flegs {441#[allow(unused_imports)]442use wasmtime::component::__internal::{anyhow, Box};443wasmtime::component::flags!(444Flag1 { #[component(name = "b0")] const B0; }445);446const _: () = {447assert!(4481 == < Flag1 as wasmtime::component::ComponentType >::SIZE32449);450assert!(4511 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32452);453};454wasmtime::component::flags!(455Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]456const B1; }457);458const _: () = {459assert!(4601 == < Flag2 as wasmtime::component::ComponentType >::SIZE32461);462assert!(4631 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32464);465};466wasmtime::component::flags!(467Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]468const B1; #[component(name = "b2")] const B2; #[component(name =469"b3")] const B3; }470);471const _: () = {472assert!(4731 == < Flag4 as wasmtime::component::ComponentType >::SIZE32474);475assert!(4761 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32477);478};479wasmtime::component::flags!(480Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]481const B1; #[component(name = "b2")] const B2; #[component(name =482"b3")] const B3; #[component(name = "b4")] const B4; #[component(name483= "b5")] const B5; #[component(name = "b6")] const B6;484#[component(name = "b7")] const B7; }485);486const _: () = {487assert!(4881 == < Flag8 as wasmtime::component::ComponentType >::SIZE32489);490assert!(4911 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32492);493};494wasmtime::component::flags!(495Flag16 { #[component(name = "b0")] const B0; #[component(name =496"b1")] const B1; #[component(name = "b2")] const B2; #[component(name497= "b3")] const B3; #[component(name = "b4")] const B4;498#[component(name = "b5")] const B5; #[component(name = "b6")] const499B6; #[component(name = "b7")] const B7; #[component(name = "b8")]500const B8; #[component(name = "b9")] const B9; #[component(name =501"b10")] const B10; #[component(name = "b11")] const B11;502#[component(name = "b12")] const B12; #[component(name = "b13")]503const B13; #[component(name = "b14")] const B14; #[component(name =504"b15")] const B15; }505);506const _: () = {507assert!(5082 == < Flag16 as wasmtime::component::ComponentType >::SIZE32509);510assert!(5112 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32512);513};514wasmtime::component::flags!(515Flag32 { #[component(name = "b0")] const B0; #[component(name =516"b1")] const B1; #[component(name = "b2")] const B2; #[component(name517= "b3")] const B3; #[component(name = "b4")] const B4;518#[component(name = "b5")] const B5; #[component(name = "b6")] const519B6; #[component(name = "b7")] const B7; #[component(name = "b8")]520const B8; #[component(name = "b9")] const B9; #[component(name =521"b10")] const B10; #[component(name = "b11")] const B11;522#[component(name = "b12")] const B12; #[component(name = "b13")]523const B13; #[component(name = "b14")] const B14; #[component(name =524"b15")] const B15; #[component(name = "b16")] const B16;525#[component(name = "b17")] const B17; #[component(name = "b18")]526const B18; #[component(name = "b19")] const B19; #[component(name =527"b20")] const B20; #[component(name = "b21")] const B21;528#[component(name = "b22")] const B22; #[component(name = "b23")]529const B23; #[component(name = "b24")] const B24; #[component(name =530"b25")] const B25; #[component(name = "b26")] const B26;531#[component(name = "b27")] const B27; #[component(name = "b28")]532const B28; #[component(name = "b29")] const B29; #[component(name =533"b30")] const B30; #[component(name = "b31")] const B31; }534);535const _: () = {536assert!(5374 == < Flag32 as wasmtime::component::ComponentType >::SIZE32538);539assert!(5404 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32541);542};543wasmtime::component::flags!(544Flag64 { #[component(name = "b0")] const B0; #[component(name =545"b1")] const B1; #[component(name = "b2")] const B2; #[component(name546= "b3")] const B3; #[component(name = "b4")] const B4;547#[component(name = "b5")] const B5; #[component(name = "b6")] const548B6; #[component(name = "b7")] const B7; #[component(name = "b8")]549const B8; #[component(name = "b9")] const B9; #[component(name =550"b10")] const B10; #[component(name = "b11")] const B11;551#[component(name = "b12")] const B12; #[component(name = "b13")]552const B13; #[component(name = "b14")] const B14; #[component(name =553"b15")] const B15; #[component(name = "b16")] const B16;554#[component(name = "b17")] const B17; #[component(name = "b18")]555const B18; #[component(name = "b19")] const B19; #[component(name =556"b20")] const B20; #[component(name = "b21")] const B21;557#[component(name = "b22")] const B22; #[component(name = "b23")]558const B23; #[component(name = "b24")] const B24; #[component(name =559"b25")] const B25; #[component(name = "b26")] const B26;560#[component(name = "b27")] const B27; #[component(name = "b28")]561const B28; #[component(name = "b29")] const B29; #[component(name =562"b30")] const B30; #[component(name = "b31")] const B31;563#[component(name = "b32")] const B32; #[component(name = "b33")]564const B33; #[component(name = "b34")] const B34; #[component(name =565"b35")] const B35; #[component(name = "b36")] const B36;566#[component(name = "b37")] const B37; #[component(name = "b38")]567const B38; #[component(name = "b39")] const B39; #[component(name =568"b40")] const B40; #[component(name = "b41")] const B41;569#[component(name = "b42")] const B42; #[component(name = "b43")]570const B43; #[component(name = "b44")] const B44; #[component(name =571"b45")] const B45; #[component(name = "b46")] const B46;572#[component(name = "b47")] const B47; #[component(name = "b48")]573const B48; #[component(name = "b49")] const B49; #[component(name =574"b50")] const B50; #[component(name = "b51")] const B51;575#[component(name = "b52")] const B52; #[component(name = "b53")]576const B53; #[component(name = "b54")] const B54; #[component(name =577"b55")] const B55; #[component(name = "b56")] const B56;578#[component(name = "b57")] const B57; #[component(name = "b58")]579const B58; #[component(name = "b59")] const B59; #[component(name =580"b60")] const B60; #[component(name = "b61")] const B61;581#[component(name = "b62")] const B62; #[component(name = "b63")]582const B63; }583);584const _: () = {585assert!(5868 == < Flag64 as wasmtime::component::ComponentType >::SIZE32587);588assert!(5894 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32590);591};592pub struct Guest {593roundtrip_flag1: wasmtime::component::Func,594roundtrip_flag2: wasmtime::component::Func,595roundtrip_flag4: wasmtime::component::Func,596roundtrip_flag8: wasmtime::component::Func,597roundtrip_flag16: wasmtime::component::Func,598roundtrip_flag32: wasmtime::component::Func,599roundtrip_flag64: wasmtime::component::Func,600}601#[derive(Clone)]602pub struct GuestIndices {603roundtrip_flag1: wasmtime::component::ComponentExportIndex,604roundtrip_flag2: wasmtime::component::ComponentExportIndex,605roundtrip_flag4: wasmtime::component::ComponentExportIndex,606roundtrip_flag8: wasmtime::component::ComponentExportIndex,607roundtrip_flag16: wasmtime::component::ComponentExportIndex,608roundtrip_flag32: wasmtime::component::ComponentExportIndex,609roundtrip_flag64: wasmtime::component::ComponentExportIndex,610}611impl GuestIndices {612/// Constructor for [`GuestIndices`] which takes a613/// [`Component`](wasmtime::component::Component) as input and can be executed614/// before instantiation.615///616/// This constructor can be used to front-load string lookups to find exports617/// within a component.618pub fn new<_T>(619_instance_pre: &wasmtime::component::InstancePre<_T>,620) -> wasmtime::Result<GuestIndices> {621let instance = _instance_pre622.component()623.get_export_index(None, "foo:foo/flegs")624.ok_or_else(|| {625anyhow::anyhow!(626"no exported instance named `foo:foo/flegs`"627)628})?;629let mut lookup = move |name| {630_instance_pre631.component()632.get_export_index(Some(&instance), name)633.ok_or_else(|| {634anyhow::anyhow!(635"instance export `foo:foo/flegs` does \636not have export `{name}`"637)638})639};640let _ = &mut lookup;641let roundtrip_flag1 = lookup("roundtrip-flag1")?;642let roundtrip_flag2 = lookup("roundtrip-flag2")?;643let roundtrip_flag4 = lookup("roundtrip-flag4")?;644let roundtrip_flag8 = lookup("roundtrip-flag8")?;645let roundtrip_flag16 = lookup("roundtrip-flag16")?;646let roundtrip_flag32 = lookup("roundtrip-flag32")?;647let roundtrip_flag64 = lookup("roundtrip-flag64")?;648Ok(GuestIndices {649roundtrip_flag1,650roundtrip_flag2,651roundtrip_flag4,652roundtrip_flag8,653roundtrip_flag16,654roundtrip_flag32,655roundtrip_flag64,656})657}658pub fn load(659&self,660mut store: impl wasmtime::AsContextMut,661instance: &wasmtime::component::Instance,662) -> wasmtime::Result<Guest> {663let _instance = instance;664let _instance_pre = _instance.instance_pre(&store);665let _instance_type = _instance_pre.instance_type();666let mut store = store.as_context_mut();667let _ = &mut store;668let roundtrip_flag1 = *_instance669.get_typed_func::<670(Flag1,),671(Flag1,),672>(&mut store, &self.roundtrip_flag1)?673.func();674let roundtrip_flag2 = *_instance675.get_typed_func::<676(Flag2,),677(Flag2,),678>(&mut store, &self.roundtrip_flag2)?679.func();680let roundtrip_flag4 = *_instance681.get_typed_func::<682(Flag4,),683(Flag4,),684>(&mut store, &self.roundtrip_flag4)?685.func();686let roundtrip_flag8 = *_instance687.get_typed_func::<688(Flag8,),689(Flag8,),690>(&mut store, &self.roundtrip_flag8)?691.func();692let roundtrip_flag16 = *_instance693.get_typed_func::<694(Flag16,),695(Flag16,),696>(&mut store, &self.roundtrip_flag16)?697.func();698let roundtrip_flag32 = *_instance699.get_typed_func::<700(Flag32,),701(Flag32,),702>(&mut store, &self.roundtrip_flag32)?703.func();704let roundtrip_flag64 = *_instance705.get_typed_func::<706(Flag64,),707(Flag64,),708>(&mut store, &self.roundtrip_flag64)?709.func();710Ok(Guest {711roundtrip_flag1,712roundtrip_flag2,713roundtrip_flag4,714roundtrip_flag8,715roundtrip_flag16,716roundtrip_flag32,717roundtrip_flag64,718})719}720}721impl Guest {722pub fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(723&self,724mut store: S,725arg0: Flag1,726) -> wasmtime::Result<Flag1> {727let callee = unsafe {728wasmtime::component::TypedFunc::<729(Flag1,),730(Flag1,),731>::new_unchecked(self.roundtrip_flag1)732};733let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;734callee.post_return(store.as_context_mut())?;735Ok(ret0)736}737pub fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(738&self,739mut store: S,740arg0: Flag2,741) -> wasmtime::Result<Flag2> {742let callee = unsafe {743wasmtime::component::TypedFunc::<744(Flag2,),745(Flag2,),746>::new_unchecked(self.roundtrip_flag2)747};748let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;749callee.post_return(store.as_context_mut())?;750Ok(ret0)751}752pub fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(753&self,754mut store: S,755arg0: Flag4,756) -> wasmtime::Result<Flag4> {757let callee = unsafe {758wasmtime::component::TypedFunc::<759(Flag4,),760(Flag4,),761>::new_unchecked(self.roundtrip_flag4)762};763let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;764callee.post_return(store.as_context_mut())?;765Ok(ret0)766}767pub fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(768&self,769mut store: S,770arg0: Flag8,771) -> wasmtime::Result<Flag8> {772let callee = unsafe {773wasmtime::component::TypedFunc::<774(Flag8,),775(Flag8,),776>::new_unchecked(self.roundtrip_flag8)777};778let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;779callee.post_return(store.as_context_mut())?;780Ok(ret0)781}782pub fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(783&self,784mut store: S,785arg0: Flag16,786) -> wasmtime::Result<Flag16> {787let callee = unsafe {788wasmtime::component::TypedFunc::<789(Flag16,),790(Flag16,),791>::new_unchecked(self.roundtrip_flag16)792};793let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;794callee.post_return(store.as_context_mut())?;795Ok(ret0)796}797pub fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(798&self,799mut store: S,800arg0: Flag32,801) -> wasmtime::Result<Flag32> {802let callee = unsafe {803wasmtime::component::TypedFunc::<804(Flag32,),805(Flag32,),806>::new_unchecked(self.roundtrip_flag32)807};808let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;809callee.post_return(store.as_context_mut())?;810Ok(ret0)811}812pub fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(813&self,814mut store: S,815arg0: Flag64,816) -> wasmtime::Result<Flag64> {817let callee = unsafe {818wasmtime::component::TypedFunc::<819(Flag64,),820(Flag64,),821>::new_unchecked(self.roundtrip_flag64)822};823let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;824callee.post_return(store.as_context_mut())?;825Ok(ret0)826}827}828}829}830}831}832833834