Path: blob/main/crates/component-macro/tests/expanded/flags_concurrent.rs
1692 views
/// Auto-generated bindings for a pre-instantiated version of a1/// component which implements the world `the-flags`.2///3/// This structure is created through [`TheFlagsPre::new`] which4/// takes a [`InstancePre`](wasmtime::component::InstancePre) that5/// has been created through a [`Linker`](wasmtime::component::Linker).6///7/// For more information see [`TheFlags`] as well.8pub struct TheFlagsPre<T: 'static> {9instance_pre: wasmtime::component::InstancePre<T>,10indices: TheFlagsIndices,11}12impl<T: 'static> Clone for TheFlagsPre<T> {13fn clone(&self) -> Self {14Self {15instance_pre: self.instance_pre.clone(),16indices: self.indices.clone(),17}18}19}20impl<_T: 'static> TheFlagsPre<_T> {21/// Creates a new copy of `TheFlagsPre` bindings which can then22/// be used to instantiate into a particular store.23///24/// This method may fail if the component behind `instance_pre`25/// does not have the required exports.26pub fn new(27instance_pre: wasmtime::component::InstancePre<_T>,28) -> wasmtime::Result<Self> {29let indices = TheFlagsIndices::new(&instance_pre)?;30Ok(Self { instance_pre, indices })31}32pub fn engine(&self) -> &wasmtime::Engine {33self.instance_pre.engine()34}35pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {36&self.instance_pre37}38/// Instantiates a new instance of [`TheFlags`] within the39/// `store` provided.40///41/// This function will use `self` as the pre-instantiated42/// instance to perform instantiation. Afterwards the preloaded43/// indices in `self` are used to lookup all exports on the44/// resulting instance.45pub fn instantiate(46&self,47mut store: impl wasmtime::AsContextMut<Data = _T>,48) -> wasmtime::Result<TheFlags> {49let mut store = store.as_context_mut();50let instance = self.instance_pre.instantiate(&mut store)?;51self.indices.load(&mut store, &instance)52}53}54impl<_T: Send + 'static> TheFlagsPre<_T> {55/// Same as [`Self::instantiate`], except with `async`.56pub async fn instantiate_async(57&self,58mut store: impl wasmtime::AsContextMut<Data = _T>,59) -> wasmtime::Result<TheFlags> {60let mut store = store.as_context_mut();61let instance = self.instance_pre.instantiate_async(&mut store).await?;62self.indices.load(&mut store, &instance)63}64}65/// Auto-generated bindings for index of the exports of66/// `the-flags`.67///68/// This is an implementation detail of [`TheFlagsPre`] and can69/// be constructed if needed as well.70///71/// For more information see [`TheFlags`] as well.72#[derive(Clone)]73pub struct TheFlagsIndices {74interface0: exports::foo::foo::flegs::GuestIndices,75}76/// Auto-generated bindings for an instance a component which77/// implements the world `the-flags`.78///79/// This structure can be created through a number of means80/// depending on your requirements and what you have on hand:81///82/// * The most convenient way is to use83/// [`TheFlags::instantiate`] which only needs a84/// [`Store`], [`Component`], and [`Linker`].85///86/// * Alternatively you can create a [`TheFlagsPre`] ahead of87/// time with a [`Component`] to front-load string lookups88/// of exports once instead of per-instantiation. This89/// method then uses [`TheFlagsPre::instantiate`] to90/// create a [`TheFlags`].91///92/// * If you've instantiated the instance yourself already93/// then you can use [`TheFlags::new`].94///95/// These methods are all equivalent to one another and move96/// around the tradeoff of what work is performed when.97///98/// [`Store`]: wasmtime::Store99/// [`Component`]: wasmtime::component::Component100/// [`Linker`]: wasmtime::component::Linker101pub struct TheFlags {102interface0: exports::foo::foo::flegs::Guest,103}104const _: () = {105#[allow(unused_imports)]106use wasmtime::component::__internal::anyhow;107impl TheFlagsIndices {108/// Creates a new copy of `TheFlagsIndices` bindings which can then109/// be used to instantiate into a particular store.110///111/// This method may fail if the component does not have the112/// required exports.113pub fn new<_T>(114_instance_pre: &wasmtime::component::InstancePre<_T>,115) -> wasmtime::Result<Self> {116let _component = _instance_pre.component();117let _instance_type = _instance_pre.instance_type();118let interface0 = exports::foo::foo::flegs::GuestIndices::new(_instance_pre)?;119Ok(TheFlagsIndices { interface0 })120}121/// Uses the indices stored in `self` to load an instance122/// of [`TheFlags`] from the instance provided.123///124/// Note that at this time this method will additionally125/// perform type-checks of all exports.126pub fn load(127&self,128mut store: impl wasmtime::AsContextMut,129instance: &wasmtime::component::Instance,130) -> wasmtime::Result<TheFlags> {131let _ = &mut store;132let _instance = instance;133let interface0 = self.interface0.load(&mut store, &_instance)?;134Ok(TheFlags { interface0 })135}136}137impl TheFlags {138/// Convenience wrapper around [`TheFlagsPre::new`] and139/// [`TheFlagsPre::instantiate`].140pub fn instantiate<_T>(141store: impl wasmtime::AsContextMut<Data = _T>,142component: &wasmtime::component::Component,143linker: &wasmtime::component::Linker<_T>,144) -> wasmtime::Result<TheFlags> {145let pre = linker.instantiate_pre(component)?;146TheFlagsPre::new(pre)?.instantiate(store)147}148/// Convenience wrapper around [`TheFlagsIndices::new`] and149/// [`TheFlagsIndices::load`].150pub fn new(151mut store: impl wasmtime::AsContextMut,152instance: &wasmtime::component::Instance,153) -> wasmtime::Result<TheFlags> {154let indices = TheFlagsIndices::new(&instance.instance_pre(&store))?;155indices.load(&mut store, instance)156}157/// Convenience wrapper around [`TheFlagsPre::new`] and158/// [`TheFlagsPre::instantiate_async`].159pub async fn instantiate_async<_T>(160store: impl wasmtime::AsContextMut<Data = _T>,161component: &wasmtime::component::Component,162linker: &wasmtime::component::Linker<_T>,163) -> wasmtime::Result<TheFlags>164where165_T: Send,166{167let pre = linker.instantiate_pre(component)?;168TheFlagsPre::new(pre)?.instantiate_async(store).await169}170pub fn add_to_linker<T, D>(171linker: &mut wasmtime::component::Linker<T>,172host_getter: fn(&mut T) -> D::Data<'_>,173) -> wasmtime::Result<()>174where175D: foo::foo::flegs::HostWithStore + Send,176for<'a> D::Data<'a>: foo::foo::flegs::Host + Send,177T: 'static + Send,178{179foo::foo::flegs::add_to_linker::<T, D>(linker, host_getter)?;180Ok(())181}182pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest {183&self.interface0184}185}186};187pub mod foo {188pub mod foo {189#[allow(clippy::all)]190pub mod flegs {191#[allow(unused_imports)]192use wasmtime::component::__internal::{anyhow, Box};193wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; });194const _: () = {195assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32);196assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32);197};198wasmtime::component::flags!(199Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]200const B1; }201);202const _: () = {203assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32);204assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32);205};206wasmtime::component::flags!(207Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]208const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]209const B3; }210);211const _: () = {212assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32);213assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32);214};215wasmtime::component::flags!(216Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]217const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]218const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]219const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]220const B7; }221);222const _: () = {223assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32);224assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32);225};226wasmtime::component::flags!(227Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")]228const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]229const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]230const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]231const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]232const B9; #[component(name = "b10")] const B10; #[component(name =233"b11")] const B11; #[component(name = "b12")] const B12; #[component(name234= "b13")] const B13; #[component(name = "b14")] const B14;235#[component(name = "b15")] const B15; }236);237const _: () = {238assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32);239assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32);240};241wasmtime::component::flags!(242Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")]243const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]244const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]245const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]246const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]247const B9; #[component(name = "b10")] const B10; #[component(name =248"b11")] const B11; #[component(name = "b12")] const B12; #[component(name249= "b13")] const B13; #[component(name = "b14")] const B14;250#[component(name = "b15")] const B15; #[component(name = "b16")] const251B16; #[component(name = "b17")] const B17; #[component(name = "b18")]252const B18; #[component(name = "b19")] const B19; #[component(name =253"b20")] const B20; #[component(name = "b21")] const B21; #[component(name254= "b22")] const B22; #[component(name = "b23")] const B23;255#[component(name = "b24")] const B24; #[component(name = "b25")] const256B25; #[component(name = "b26")] const B26; #[component(name = "b27")]257const B27; #[component(name = "b28")] const B28; #[component(name =258"b29")] const B29; #[component(name = "b30")] const B30; #[component(name259= "b31")] const B31; }260);261const _: () = {262assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32);263assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32);264};265wasmtime::component::flags!(266Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")]267const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]268const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]269const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]270const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]271const B9; #[component(name = "b10")] const B10; #[component(name =272"b11")] const B11; #[component(name = "b12")] const B12; #[component(name273= "b13")] const B13; #[component(name = "b14")] const B14;274#[component(name = "b15")] const B15; #[component(name = "b16")] const275B16; #[component(name = "b17")] const B17; #[component(name = "b18")]276const B18; #[component(name = "b19")] const B19; #[component(name =277"b20")] const B20; #[component(name = "b21")] const B21; #[component(name278= "b22")] const B22; #[component(name = "b23")] const B23;279#[component(name = "b24")] const B24; #[component(name = "b25")] const280B25; #[component(name = "b26")] const B26; #[component(name = "b27")]281const B27; #[component(name = "b28")] const B28; #[component(name =282"b29")] const B29; #[component(name = "b30")] const B30; #[component(name283= "b31")] const B31; #[component(name = "b32")] const B32;284#[component(name = "b33")] const B33; #[component(name = "b34")] const285B34; #[component(name = "b35")] const B35; #[component(name = "b36")]286const B36; #[component(name = "b37")] const B37; #[component(name =287"b38")] const B38; #[component(name = "b39")] const B39; #[component(name288= "b40")] const B40; #[component(name = "b41")] const B41;289#[component(name = "b42")] const B42; #[component(name = "b43")] const290B43; #[component(name = "b44")] const B44; #[component(name = "b45")]291const B45; #[component(name = "b46")] const B46; #[component(name =292"b47")] const B47; #[component(name = "b48")] const B48; #[component(name293= "b49")] const B49; #[component(name = "b50")] const B50;294#[component(name = "b51")] const B51; #[component(name = "b52")] const295B52; #[component(name = "b53")] const B53; #[component(name = "b54")]296const B54; #[component(name = "b55")] const B55; #[component(name =297"b56")] const B56; #[component(name = "b57")] const B57; #[component(name298= "b58")] const B58; #[component(name = "b59")] const B59;299#[component(name = "b60")] const B60; #[component(name = "b61")] const300B61; #[component(name = "b62")] const B62; #[component(name = "b63")]301const B63; }302);303const _: () = {304assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32);305assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32);306};307pub trait HostWithStore: wasmtime::component::HasData + Send {308fn roundtrip_flag1<T>(309accessor: &wasmtime::component::Accessor<T, Self>,310x: Flag1,311) -> impl ::core::future::Future<Output = Flag1> + Send;312fn roundtrip_flag2<T>(313accessor: &wasmtime::component::Accessor<T, Self>,314x: Flag2,315) -> impl ::core::future::Future<Output = Flag2> + Send;316fn roundtrip_flag4<T>(317accessor: &wasmtime::component::Accessor<T, Self>,318x: Flag4,319) -> impl ::core::future::Future<Output = Flag4> + Send;320fn roundtrip_flag8<T>(321accessor: &wasmtime::component::Accessor<T, Self>,322x: Flag8,323) -> impl ::core::future::Future<Output = Flag8> + Send;324fn roundtrip_flag16<T>(325accessor: &wasmtime::component::Accessor<T, Self>,326x: Flag16,327) -> impl ::core::future::Future<Output = Flag16> + Send;328fn roundtrip_flag32<T>(329accessor: &wasmtime::component::Accessor<T, Self>,330x: Flag32,331) -> impl ::core::future::Future<Output = Flag32> + Send;332fn roundtrip_flag64<T>(333accessor: &wasmtime::component::Accessor<T, Self>,334x: Flag64,335) -> impl ::core::future::Future<Output = Flag64> + Send;336}337pub trait Host: Send {}338impl<_T: Host + ?Sized + Send> Host for &mut _T {}339pub fn add_to_linker<T, D>(340linker: &mut wasmtime::component::Linker<T>,341host_getter: fn(&mut T) -> D::Data<'_>,342) -> wasmtime::Result<()>343where344D: HostWithStore,345for<'a> D::Data<'a>: Host,346T: 'static + Send,347{348let mut inst = linker.instance("foo:foo/flegs")?;349inst.func_wrap_concurrent(350"roundtrip-flag1",351move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag1,)| {352wasmtime::component::__internal::Box::pin(async move {353let host = &caller.with_getter(host_getter);354let r = <D as HostWithStore>::roundtrip_flag1(host, arg0)355.await;356Ok((r,))357})358},359)?;360inst.func_wrap_concurrent(361"roundtrip-flag2",362move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag2,)| {363wasmtime::component::__internal::Box::pin(async move {364let host = &caller.with_getter(host_getter);365let r = <D as HostWithStore>::roundtrip_flag2(host, arg0)366.await;367Ok((r,))368})369},370)?;371inst.func_wrap_concurrent(372"roundtrip-flag4",373move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag4,)| {374wasmtime::component::__internal::Box::pin(async move {375let host = &caller.with_getter(host_getter);376let r = <D as HostWithStore>::roundtrip_flag4(host, arg0)377.await;378Ok((r,))379})380},381)?;382inst.func_wrap_concurrent(383"roundtrip-flag8",384move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag8,)| {385wasmtime::component::__internal::Box::pin(async move {386let host = &caller.with_getter(host_getter);387let r = <D as HostWithStore>::roundtrip_flag8(host, arg0)388.await;389Ok((r,))390})391},392)?;393inst.func_wrap_concurrent(394"roundtrip-flag16",395move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag16,)| {396wasmtime::component::__internal::Box::pin(async move {397let host = &caller.with_getter(host_getter);398let r = <D as HostWithStore>::roundtrip_flag16(host, arg0)399.await;400Ok((r,))401})402},403)?;404inst.func_wrap_concurrent(405"roundtrip-flag32",406move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag32,)| {407wasmtime::component::__internal::Box::pin(async move {408let host = &caller.with_getter(host_getter);409let r = <D as HostWithStore>::roundtrip_flag32(host, arg0)410.await;411Ok((r,))412})413},414)?;415inst.func_wrap_concurrent(416"roundtrip-flag64",417move |caller: &wasmtime::component::Accessor<T>, (arg0,): (Flag64,)| {418wasmtime::component::__internal::Box::pin(async move {419let host = &caller.with_getter(host_getter);420let r = <D as HostWithStore>::roundtrip_flag64(host, arg0)421.await;422Ok((r,))423})424},425)?;426Ok(())427}428}429}430}431pub mod exports {432pub mod foo {433pub mod foo {434#[allow(clippy::all)]435pub mod flegs {436#[allow(unused_imports)]437use wasmtime::component::__internal::{anyhow, Box};438wasmtime::component::flags!(439Flag1 { #[component(name = "b0")] const B0; }440);441const _: () = {442assert!(4431 == < Flag1 as wasmtime::component::ComponentType >::SIZE32444);445assert!(4461 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32447);448};449wasmtime::component::flags!(450Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]451const B1; }452);453const _: () = {454assert!(4551 == < Flag2 as wasmtime::component::ComponentType >::SIZE32456);457assert!(4581 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32459);460};461wasmtime::component::flags!(462Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]463const B1; #[component(name = "b2")] const B2; #[component(name =464"b3")] const B3; }465);466const _: () = {467assert!(4681 == < Flag4 as wasmtime::component::ComponentType >::SIZE32469);470assert!(4711 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32472);473};474wasmtime::component::flags!(475Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]476const B1; #[component(name = "b2")] const B2; #[component(name =477"b3")] const B3; #[component(name = "b4")] const B4; #[component(name478= "b5")] const B5; #[component(name = "b6")] const B6;479#[component(name = "b7")] const B7; }480);481const _: () = {482assert!(4831 == < Flag8 as wasmtime::component::ComponentType >::SIZE32484);485assert!(4861 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32487);488};489wasmtime::component::flags!(490Flag16 { #[component(name = "b0")] const B0; #[component(name =491"b1")] const B1; #[component(name = "b2")] const B2; #[component(name492= "b3")] const B3; #[component(name = "b4")] const B4;493#[component(name = "b5")] const B5; #[component(name = "b6")] const494B6; #[component(name = "b7")] const B7; #[component(name = "b8")]495const B8; #[component(name = "b9")] const B9; #[component(name =496"b10")] const B10; #[component(name = "b11")] const B11;497#[component(name = "b12")] const B12; #[component(name = "b13")]498const B13; #[component(name = "b14")] const B14; #[component(name =499"b15")] const B15; }500);501const _: () = {502assert!(5032 == < Flag16 as wasmtime::component::ComponentType >::SIZE32504);505assert!(5062 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32507);508};509wasmtime::component::flags!(510Flag32 { #[component(name = "b0")] const B0; #[component(name =511"b1")] const B1; #[component(name = "b2")] const B2; #[component(name512= "b3")] const B3; #[component(name = "b4")] const B4;513#[component(name = "b5")] const B5; #[component(name = "b6")] const514B6; #[component(name = "b7")] const B7; #[component(name = "b8")]515const B8; #[component(name = "b9")] const B9; #[component(name =516"b10")] const B10; #[component(name = "b11")] const B11;517#[component(name = "b12")] const B12; #[component(name = "b13")]518const B13; #[component(name = "b14")] const B14; #[component(name =519"b15")] const B15; #[component(name = "b16")] const B16;520#[component(name = "b17")] const B17; #[component(name = "b18")]521const B18; #[component(name = "b19")] const B19; #[component(name =522"b20")] const B20; #[component(name = "b21")] const B21;523#[component(name = "b22")] const B22; #[component(name = "b23")]524const B23; #[component(name = "b24")] const B24; #[component(name =525"b25")] const B25; #[component(name = "b26")] const B26;526#[component(name = "b27")] const B27; #[component(name = "b28")]527const B28; #[component(name = "b29")] const B29; #[component(name =528"b30")] const B30; #[component(name = "b31")] const B31; }529);530const _: () = {531assert!(5324 == < Flag32 as wasmtime::component::ComponentType >::SIZE32533);534assert!(5354 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32536);537};538wasmtime::component::flags!(539Flag64 { #[component(name = "b0")] const B0; #[component(name =540"b1")] const B1; #[component(name = "b2")] const B2; #[component(name541= "b3")] const B3; #[component(name = "b4")] const B4;542#[component(name = "b5")] const B5; #[component(name = "b6")] const543B6; #[component(name = "b7")] const B7; #[component(name = "b8")]544const B8; #[component(name = "b9")] const B9; #[component(name =545"b10")] const B10; #[component(name = "b11")] const B11;546#[component(name = "b12")] const B12; #[component(name = "b13")]547const B13; #[component(name = "b14")] const B14; #[component(name =548"b15")] const B15; #[component(name = "b16")] const B16;549#[component(name = "b17")] const B17; #[component(name = "b18")]550const B18; #[component(name = "b19")] const B19; #[component(name =551"b20")] const B20; #[component(name = "b21")] const B21;552#[component(name = "b22")] const B22; #[component(name = "b23")]553const B23; #[component(name = "b24")] const B24; #[component(name =554"b25")] const B25; #[component(name = "b26")] const B26;555#[component(name = "b27")] const B27; #[component(name = "b28")]556const B28; #[component(name = "b29")] const B29; #[component(name =557"b30")] const B30; #[component(name = "b31")] const B31;558#[component(name = "b32")] const B32; #[component(name = "b33")]559const B33; #[component(name = "b34")] const B34; #[component(name =560"b35")] const B35; #[component(name = "b36")] const B36;561#[component(name = "b37")] const B37; #[component(name = "b38")]562const B38; #[component(name = "b39")] const B39; #[component(name =563"b40")] const B40; #[component(name = "b41")] const B41;564#[component(name = "b42")] const B42; #[component(name = "b43")]565const B43; #[component(name = "b44")] const B44; #[component(name =566"b45")] const B45; #[component(name = "b46")] const B46;567#[component(name = "b47")] const B47; #[component(name = "b48")]568const B48; #[component(name = "b49")] const B49; #[component(name =569"b50")] const B50; #[component(name = "b51")] const B51;570#[component(name = "b52")] const B52; #[component(name = "b53")]571const B53; #[component(name = "b54")] const B54; #[component(name =572"b55")] const B55; #[component(name = "b56")] const B56;573#[component(name = "b57")] const B57; #[component(name = "b58")]574const B58; #[component(name = "b59")] const B59; #[component(name =575"b60")] const B60; #[component(name = "b61")] const B61;576#[component(name = "b62")] const B62; #[component(name = "b63")]577const B63; }578);579const _: () = {580assert!(5818 == < Flag64 as wasmtime::component::ComponentType >::SIZE32582);583assert!(5844 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32585);586};587pub struct Guest {588roundtrip_flag1: wasmtime::component::Func,589roundtrip_flag2: wasmtime::component::Func,590roundtrip_flag4: wasmtime::component::Func,591roundtrip_flag8: wasmtime::component::Func,592roundtrip_flag16: wasmtime::component::Func,593roundtrip_flag32: wasmtime::component::Func,594roundtrip_flag64: wasmtime::component::Func,595}596#[derive(Clone)]597pub struct GuestIndices {598roundtrip_flag1: wasmtime::component::ComponentExportIndex,599roundtrip_flag2: wasmtime::component::ComponentExportIndex,600roundtrip_flag4: wasmtime::component::ComponentExportIndex,601roundtrip_flag8: wasmtime::component::ComponentExportIndex,602roundtrip_flag16: wasmtime::component::ComponentExportIndex,603roundtrip_flag32: wasmtime::component::ComponentExportIndex,604roundtrip_flag64: wasmtime::component::ComponentExportIndex,605}606impl GuestIndices {607/// Constructor for [`GuestIndices`] which takes a608/// [`Component`](wasmtime::component::Component) as input and can be executed609/// before instantiation.610///611/// This constructor can be used to front-load string lookups to find exports612/// within a component.613pub fn new<_T>(614_instance_pre: &wasmtime::component::InstancePre<_T>,615) -> wasmtime::Result<GuestIndices> {616let instance = _instance_pre617.component()618.get_export_index(None, "foo:foo/flegs")619.ok_or_else(|| {620anyhow::anyhow!(621"no exported instance named `foo:foo/flegs`"622)623})?;624let mut lookup = move |name| {625_instance_pre626.component()627.get_export_index(Some(&instance), name)628.ok_or_else(|| {629anyhow::anyhow!(630"instance export `foo:foo/flegs` does \631not have export `{name}`"632)633})634};635let _ = &mut lookup;636let roundtrip_flag1 = lookup("roundtrip-flag1")?;637let roundtrip_flag2 = lookup("roundtrip-flag2")?;638let roundtrip_flag4 = lookup("roundtrip-flag4")?;639let roundtrip_flag8 = lookup("roundtrip-flag8")?;640let roundtrip_flag16 = lookup("roundtrip-flag16")?;641let roundtrip_flag32 = lookup("roundtrip-flag32")?;642let roundtrip_flag64 = lookup("roundtrip-flag64")?;643Ok(GuestIndices {644roundtrip_flag1,645roundtrip_flag2,646roundtrip_flag4,647roundtrip_flag8,648roundtrip_flag16,649roundtrip_flag32,650roundtrip_flag64,651})652}653pub fn load(654&self,655mut store: impl wasmtime::AsContextMut,656instance: &wasmtime::component::Instance,657) -> wasmtime::Result<Guest> {658let _instance = instance;659let _instance_pre = _instance.instance_pre(&store);660let _instance_type = _instance_pre.instance_type();661let mut store = store.as_context_mut();662let _ = &mut store;663let roundtrip_flag1 = *_instance664.get_typed_func::<665(Flag1,),666(Flag1,),667>(&mut store, &self.roundtrip_flag1)?668.func();669let roundtrip_flag2 = *_instance670.get_typed_func::<671(Flag2,),672(Flag2,),673>(&mut store, &self.roundtrip_flag2)?674.func();675let roundtrip_flag4 = *_instance676.get_typed_func::<677(Flag4,),678(Flag4,),679>(&mut store, &self.roundtrip_flag4)?680.func();681let roundtrip_flag8 = *_instance682.get_typed_func::<683(Flag8,),684(Flag8,),685>(&mut store, &self.roundtrip_flag8)?686.func();687let roundtrip_flag16 = *_instance688.get_typed_func::<689(Flag16,),690(Flag16,),691>(&mut store, &self.roundtrip_flag16)?692.func();693let roundtrip_flag32 = *_instance694.get_typed_func::<695(Flag32,),696(Flag32,),697>(&mut store, &self.roundtrip_flag32)?698.func();699let roundtrip_flag64 = *_instance700.get_typed_func::<701(Flag64,),702(Flag64,),703>(&mut store, &self.roundtrip_flag64)?704.func();705Ok(Guest {706roundtrip_flag1,707roundtrip_flag2,708roundtrip_flag4,709roundtrip_flag8,710roundtrip_flag16,711roundtrip_flag32,712roundtrip_flag64,713})714}715}716impl Guest {717pub async fn call_roundtrip_flag1<_T, _D>(718&self,719accessor: &wasmtime::component::Accessor<_T, _D>,720arg0: Flag1,721) -> wasmtime::Result<Flag1>722where723_T: Send,724_D: wasmtime::component::HasData,725{726let callee = unsafe {727wasmtime::component::TypedFunc::<728(Flag1,),729(Flag1,),730>::new_unchecked(self.roundtrip_flag1)731};732let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;733Ok(ret0)734}735pub async fn call_roundtrip_flag2<_T, _D>(736&self,737accessor: &wasmtime::component::Accessor<_T, _D>,738arg0: Flag2,739) -> wasmtime::Result<Flag2>740where741_T: Send,742_D: wasmtime::component::HasData,743{744let callee = unsafe {745wasmtime::component::TypedFunc::<746(Flag2,),747(Flag2,),748>::new_unchecked(self.roundtrip_flag2)749};750let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;751Ok(ret0)752}753pub async fn call_roundtrip_flag4<_T, _D>(754&self,755accessor: &wasmtime::component::Accessor<_T, _D>,756arg0: Flag4,757) -> wasmtime::Result<Flag4>758where759_T: Send,760_D: wasmtime::component::HasData,761{762let callee = unsafe {763wasmtime::component::TypedFunc::<764(Flag4,),765(Flag4,),766>::new_unchecked(self.roundtrip_flag4)767};768let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;769Ok(ret0)770}771pub async fn call_roundtrip_flag8<_T, _D>(772&self,773accessor: &wasmtime::component::Accessor<_T, _D>,774arg0: Flag8,775) -> wasmtime::Result<Flag8>776where777_T: Send,778_D: wasmtime::component::HasData,779{780let callee = unsafe {781wasmtime::component::TypedFunc::<782(Flag8,),783(Flag8,),784>::new_unchecked(self.roundtrip_flag8)785};786let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;787Ok(ret0)788}789pub async fn call_roundtrip_flag16<_T, _D>(790&self,791accessor: &wasmtime::component::Accessor<_T, _D>,792arg0: Flag16,793) -> wasmtime::Result<Flag16>794where795_T: Send,796_D: wasmtime::component::HasData,797{798let callee = unsafe {799wasmtime::component::TypedFunc::<800(Flag16,),801(Flag16,),802>::new_unchecked(self.roundtrip_flag16)803};804let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;805Ok(ret0)806}807pub async fn call_roundtrip_flag32<_T, _D>(808&self,809accessor: &wasmtime::component::Accessor<_T, _D>,810arg0: Flag32,811) -> wasmtime::Result<Flag32>812where813_T: Send,814_D: wasmtime::component::HasData,815{816let callee = unsafe {817wasmtime::component::TypedFunc::<818(Flag32,),819(Flag32,),820>::new_unchecked(self.roundtrip_flag32)821};822let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;823Ok(ret0)824}825pub async fn call_roundtrip_flag64<_T, _D>(826&self,827accessor: &wasmtime::component::Accessor<_T, _D>,828arg0: Flag64,829) -> wasmtime::Result<Flag64>830where831_T: Send,832_D: wasmtime::component::HasData,833{834let callee = unsafe {835wasmtime::component::TypedFunc::<836(Flag64,),837(Flag64,),838>::new_unchecked(self.roundtrip_flag64)839};840let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;841Ok(ret0)842}843}844}845}846}847}848849850