Path: blob/main/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs
3092 views
/// Auto-generated bindings for a pre-instantiated version of a1/// component which implements the world `the-world`.2///3/// This structure is created through [`TheWorldPre::new`] which4/// takes a [`InstancePre`](wasmtime::component::InstancePre) that5/// has been created through a [`Linker`](wasmtime::component::Linker).6///7/// For more information see [`TheWorld`] as well.8pub struct TheWorldPre<T: 'static> {9instance_pre: wasmtime::component::InstancePre<T>,10indices: TheWorldIndices,11}12impl<T: 'static> Clone for TheWorldPre<T> {13fn clone(&self) -> Self {14Self {15instance_pre: self.instance_pre.clone(),16indices: self.indices.clone(),17}18}19}20impl<_T: 'static> TheWorldPre<_T> {21/// Creates a new copy of `TheWorldPre` 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 = TheWorldIndices::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 [`TheWorld`] 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<TheWorld> {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> TheWorldPre<_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<TheWorld> {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-world`.67///68/// This is an implementation detail of [`TheWorldPre`] and can69/// be constructed if needed as well.70///71/// For more information see [`TheWorld`] as well.72#[derive(Clone)]73pub struct TheWorldIndices {74interface0: exports::foo::foo::manyarg::GuestIndices,75}76/// Auto-generated bindings for an instance a component which77/// implements the world `the-world`.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/// [`TheWorld::instantiate`] which only needs a84/// [`Store`], [`Component`], and [`Linker`].85///86/// * Alternatively you can create a [`TheWorldPre`] ahead of87/// time with a [`Component`] to front-load string lookups88/// of exports once instead of per-instantiation. This89/// method then uses [`TheWorldPre::instantiate`] to90/// create a [`TheWorld`].91///92/// * If you've instantiated the instance yourself already93/// then you can use [`TheWorld::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 TheWorld {102interface0: exports::foo::foo::manyarg::Guest,103}104const _: () = {105impl TheWorldIndices {106/// Creates a new copy of `TheWorldIndices` 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::manyarg::GuestIndices::new(117_instance_pre,118)?;119Ok(TheWorldIndices { interface0 })120}121/// Uses the indices stored in `self` to load an instance122/// of [`TheWorld`] 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<TheWorld> {131let _ = &mut store;132let _instance = instance;133let interface0 = self.interface0.load(&mut store, &_instance)?;134Ok(TheWorld { interface0 })135}136}137impl TheWorld {138/// Convenience wrapper around [`TheWorldPre::new`] and139/// [`TheWorldPre::instantiate`].140pub fn instantiate<_T>(141store: impl wasmtime::AsContextMut<Data = _T>,142component: &wasmtime::component::Component,143linker: &wasmtime::component::Linker<_T>,144) -> wasmtime::Result<TheWorld> {145let pre = linker.instantiate_pre(component)?;146TheWorldPre::new(pre)?.instantiate(store)147}148/// Convenience wrapper around [`TheWorldIndices::new`] and149/// [`TheWorldIndices::load`].150pub fn new(151mut store: impl wasmtime::AsContextMut,152instance: &wasmtime::component::Instance,153) -> wasmtime::Result<TheWorld> {154let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;155indices.load(&mut store, instance)156}157/// Convenience wrapper around [`TheWorldPre::new`] and158/// [`TheWorldPre::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<TheWorld>164where165_T: Send,166{167let pre = linker.instantiate_pre(component)?;168TheWorldPre::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::manyarg::HostWithStore + Send,176for<'a> D::Data<'a>: foo::foo::manyarg::Host + Send,177T: 'static + Send,178{179foo::foo::manyarg::add_to_linker::<T, D>(linker, host_getter)?;180Ok(())181}182pub fn foo_foo_manyarg(&self) -> &exports::foo::foo::manyarg::Guest {183&self.interface0184}185}186};187pub mod foo {188pub mod foo {189#[allow(clippy::all)]190pub mod manyarg {191#[allow(unused_imports)]192use wasmtime::component::__internal::Box;193#[derive(wasmtime::component::ComponentType)]194#[derive(wasmtime::component::Lift)]195#[derive(wasmtime::component::Lower)]196#[component(record)]197#[derive(Clone)]198pub struct BigStruct {199#[component(name = "a1")]200pub a1: wasmtime::component::__internal::String,201#[component(name = "a2")]202pub a2: wasmtime::component::__internal::String,203#[component(name = "a3")]204pub a3: wasmtime::component::__internal::String,205#[component(name = "a4")]206pub a4: wasmtime::component::__internal::String,207#[component(name = "a5")]208pub a5: wasmtime::component::__internal::String,209#[component(name = "a6")]210pub a6: wasmtime::component::__internal::String,211#[component(name = "a7")]212pub a7: wasmtime::component::__internal::String,213#[component(name = "a8")]214pub a8: wasmtime::component::__internal::String,215#[component(name = "a9")]216pub a9: wasmtime::component::__internal::String,217#[component(name = "a10")]218pub a10: wasmtime::component::__internal::String,219#[component(name = "a11")]220pub a11: wasmtime::component::__internal::String,221#[component(name = "a12")]222pub a12: wasmtime::component::__internal::String,223#[component(name = "a13")]224pub a13: wasmtime::component::__internal::String,225#[component(name = "a14")]226pub a14: wasmtime::component::__internal::String,227#[component(name = "a15")]228pub a15: wasmtime::component::__internal::String,229#[component(name = "a16")]230pub a16: wasmtime::component::__internal::String,231#[component(name = "a17")]232pub a17: wasmtime::component::__internal::String,233#[component(name = "a18")]234pub a18: wasmtime::component::__internal::String,235#[component(name = "a19")]236pub a19: wasmtime::component::__internal::String,237#[component(name = "a20")]238pub a20: wasmtime::component::__internal::String,239}240impl core::fmt::Debug for BigStruct {241fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {242f.debug_struct("BigStruct")243.field("a1", &self.a1)244.field("a2", &self.a2)245.field("a3", &self.a3)246.field("a4", &self.a4)247.field("a5", &self.a5)248.field("a6", &self.a6)249.field("a7", &self.a7)250.field("a8", &self.a8)251.field("a9", &self.a9)252.field("a10", &self.a10)253.field("a11", &self.a11)254.field("a12", &self.a12)255.field("a13", &self.a13)256.field("a14", &self.a14)257.field("a15", &self.a15)258.field("a16", &self.a16)259.field("a17", &self.a17)260.field("a18", &self.a18)261.field("a19", &self.a19)262.field("a20", &self.a20)263.finish()264}265}266const _: () = {267assert!(268160 == < BigStruct as wasmtime::component::ComponentType >::SIZE32269);270assert!(2714 == < BigStruct as wasmtime::component::ComponentType >::ALIGN32272);273};274pub trait HostWithStore: wasmtime::component::HasData + Send {}275impl<_T: ?Sized> HostWithStore for _T276where277_T: wasmtime::component::HasData + Send,278{}279pub trait Host: Send {280fn many_args(281&mut self,282a1: u64,283a2: u64,284a3: u64,285a4: u64,286a5: u64,287a6: u64,288a7: u64,289a8: u64,290a9: u64,291a10: u64,292a11: u64,293a12: u64,294a13: u64,295a14: u64,296a15: u64,297a16: u64,298) -> impl ::core::future::Future<Output = ()> + Send;299fn big_argument(300&mut self,301x: BigStruct,302) -> impl ::core::future::Future<Output = ()> + Send;303}304impl<_T: Host + ?Sized + Send> Host for &mut _T {305fn many_args(306&mut self,307a1: u64,308a2: u64,309a3: u64,310a4: u64,311a5: u64,312a6: u64,313a7: u64,314a8: u64,315a9: u64,316a10: u64,317a11: u64,318a12: u64,319a13: u64,320a14: u64,321a15: u64,322a16: u64,323) -> impl ::core::future::Future<Output = ()> + Send {324async move {325Host::many_args(326*self,327a1,328a2,329a3,330a4,331a5,332a6,333a7,334a8,335a9,336a10,337a11,338a12,339a13,340a14,341a15,342a16,343)344.await345}346}347fn big_argument(348&mut self,349x: BigStruct,350) -> impl ::core::future::Future<Output = ()> + Send {351async move { Host::big_argument(*self, x).await }352}353}354pub fn add_to_linker<T, D>(355linker: &mut wasmtime::component::Linker<T>,356host_getter: fn(&mut T) -> D::Data<'_>,357) -> wasmtime::Result<()>358where359D: HostWithStore,360for<'a> D::Data<'a>: Host,361T: 'static + Send,362{363let mut inst = linker.instance("foo:foo/manyarg")?;364inst.func_wrap_async(365"many-args",366move |367mut caller: wasmtime::StoreContextMut<'_, T>,368(369arg0,370arg1,371arg2,372arg3,373arg4,374arg5,375arg6,376arg7,377arg8,378arg9,379arg10,380arg11,381arg12,382arg13,383arg14,384arg15,385): (386u64,387u64,388u64,389u64,390u64,391u64,392u64,393u64,394u64,395u64,396u64,397u64,398u64,399u64,400u64,401u64,402)|403{404use tracing::Instrument;405let span = tracing::span!(406tracing::Level::TRACE, "wit-bindgen import", module =407"manyarg", function = "many-args",408);409wasmtime::component::__internal::Box::new(410async move {411tracing::event!(412tracing::Level::TRACE, a1 = tracing::field::debug(& arg0),413a2 = tracing::field::debug(& arg1), a3 =414tracing::field::debug(& arg2), a4 = tracing::field::debug(&415arg3), a5 = tracing::field::debug(& arg4), a6 =416tracing::field::debug(& arg5), a7 = tracing::field::debug(&417arg6), a8 = tracing::field::debug(& arg7), a9 =418tracing::field::debug(& arg8), a10 = tracing::field::debug(&419arg9), a11 = tracing::field::debug(& arg10), a12 =420tracing::field::debug(& arg11), a13 =421tracing::field::debug(& arg12), a14 =422tracing::field::debug(& arg13), a15 =423tracing::field::debug(& arg14), a16 =424tracing::field::debug(& arg15), "call"425);426let host = &mut host_getter(caller.data_mut());427let r = Host::many_args(428host,429arg0,430arg1,431arg2,432arg3,433arg4,434arg5,435arg6,436arg7,437arg8,438arg9,439arg10,440arg11,441arg12,442arg13,443arg14,444arg15,445)446.await;447tracing::event!(448tracing::Level::TRACE, result = tracing::field::debug(& r),449"return"450);451Ok(r)452}453.instrument(span),454)455},456)?;457inst.func_wrap_async(458"big-argument",459move |460mut caller: wasmtime::StoreContextMut<'_, T>,461(arg0,): (BigStruct,)|462{463use tracing::Instrument;464let span = tracing::span!(465tracing::Level::TRACE, "wit-bindgen import", module =466"manyarg", function = "big-argument",467);468wasmtime::component::__internal::Box::new(469async move {470tracing::event!(471tracing::Level::TRACE, x = tracing::field::debug(& arg0),472"call"473);474let host = &mut host_getter(caller.data_mut());475let r = Host::big_argument(host, arg0).await;476tracing::event!(477tracing::Level::TRACE, result = tracing::field::debug(& r),478"return"479);480Ok(r)481}482.instrument(span),483)484},485)?;486Ok(())487}488}489}490}491pub mod exports {492pub mod foo {493pub mod foo {494#[allow(clippy::all)]495pub mod manyarg {496#[allow(unused_imports)]497use wasmtime::component::__internal::Box;498#[derive(wasmtime::component::ComponentType)]499#[derive(wasmtime::component::Lift)]500#[derive(wasmtime::component::Lower)]501#[component(record)]502#[derive(Clone)]503pub struct BigStruct {504#[component(name = "a1")]505pub a1: wasmtime::component::__internal::String,506#[component(name = "a2")]507pub a2: wasmtime::component::__internal::String,508#[component(name = "a3")]509pub a3: wasmtime::component::__internal::String,510#[component(name = "a4")]511pub a4: wasmtime::component::__internal::String,512#[component(name = "a5")]513pub a5: wasmtime::component::__internal::String,514#[component(name = "a6")]515pub a6: wasmtime::component::__internal::String,516#[component(name = "a7")]517pub a7: wasmtime::component::__internal::String,518#[component(name = "a8")]519pub a8: wasmtime::component::__internal::String,520#[component(name = "a9")]521pub a9: wasmtime::component::__internal::String,522#[component(name = "a10")]523pub a10: wasmtime::component::__internal::String,524#[component(name = "a11")]525pub a11: wasmtime::component::__internal::String,526#[component(name = "a12")]527pub a12: wasmtime::component::__internal::String,528#[component(name = "a13")]529pub a13: wasmtime::component::__internal::String,530#[component(name = "a14")]531pub a14: wasmtime::component::__internal::String,532#[component(name = "a15")]533pub a15: wasmtime::component::__internal::String,534#[component(name = "a16")]535pub a16: wasmtime::component::__internal::String,536#[component(name = "a17")]537pub a17: wasmtime::component::__internal::String,538#[component(name = "a18")]539pub a18: wasmtime::component::__internal::String,540#[component(name = "a19")]541pub a19: wasmtime::component::__internal::String,542#[component(name = "a20")]543pub a20: wasmtime::component::__internal::String,544}545impl core::fmt::Debug for BigStruct {546fn fmt(547&self,548f: &mut core::fmt::Formatter<'_>,549) -> core::fmt::Result {550f.debug_struct("BigStruct")551.field("a1", &self.a1)552.field("a2", &self.a2)553.field("a3", &self.a3)554.field("a4", &self.a4)555.field("a5", &self.a5)556.field("a6", &self.a6)557.field("a7", &self.a7)558.field("a8", &self.a8)559.field("a9", &self.a9)560.field("a10", &self.a10)561.field("a11", &self.a11)562.field("a12", &self.a12)563.field("a13", &self.a13)564.field("a14", &self.a14)565.field("a15", &self.a15)566.field("a16", &self.a16)567.field("a17", &self.a17)568.field("a18", &self.a18)569.field("a19", &self.a19)570.field("a20", &self.a20)571.finish()572}573}574const _: () = {575assert!(576160 == < BigStruct as wasmtime::component::ComponentType577>::SIZE32578);579assert!(5804 == < BigStruct as wasmtime::component::ComponentType >::ALIGN32581);582};583#[derive(Clone)]584pub struct Guest {585many_args: wasmtime::component::Func,586big_argument: wasmtime::component::Func,587}588#[derive(Clone)]589pub struct GuestIndices {590many_args: wasmtime::component::ComponentExportIndex,591big_argument: wasmtime::component::ComponentExportIndex,592}593impl GuestIndices {594/// Constructor for [`GuestIndices`] which takes a595/// [`Component`](wasmtime::component::Component) as input and can be executed596/// before instantiation.597///598/// This constructor can be used to front-load string lookups to find exports599/// within a component.600pub fn new<_T>(601_instance_pre: &wasmtime::component::InstancePre<_T>,602) -> wasmtime::Result<GuestIndices> {603let instance = _instance_pre604.component()605.get_export_index(None, "foo:foo/manyarg")606.ok_or_else(|| {607wasmtime::format_err!(608"no exported instance named `foo:foo/manyarg`"609)610})?;611let mut lookup = move |name| {612_instance_pre613.component()614.get_export_index(Some(&instance), name)615.ok_or_else(|| {616wasmtime::format_err!(617"instance export `foo:foo/manyarg` does \618not have export `{name}`"619)620})621};622let _ = &mut lookup;623let many_args = lookup("many-args")?;624let big_argument = lookup("big-argument")?;625Ok(GuestIndices {626many_args,627big_argument,628})629}630pub fn load(631&self,632mut store: impl wasmtime::AsContextMut,633instance: &wasmtime::component::Instance,634) -> wasmtime::Result<Guest> {635let _instance = instance;636let _instance_pre = _instance.instance_pre(&store);637let _instance_type = _instance_pre.instance_type();638let mut store = store.as_context_mut();639let _ = &mut store;640let many_args = *_instance641.get_typed_func::<642(643u64,644u64,645u64,646u64,647u64,648u64,649u64,650u64,651u64,652u64,653u64,654u64,655u64,656u64,657u64,658u64,659),660(),661>(&mut store, &self.many_args)?662.func();663let big_argument = *_instance664.get_typed_func::<665(&BigStruct,),666(),667>(&mut store, &self.big_argument)?668.func();669Ok(Guest { many_args, big_argument })670}671}672impl Guest {673pub async fn call_many_args<S: wasmtime::AsContextMut>(674&self,675mut store: S,676arg0: u64,677arg1: u64,678arg2: u64,679arg3: u64,680arg4: u64,681arg5: u64,682arg6: u64,683arg7: u64,684arg8: u64,685arg9: u64,686arg10: u64,687arg11: u64,688arg12: u64,689arg13: u64,690arg14: u64,691arg15: u64,692) -> wasmtime::Result<()>693where694<S as wasmtime::AsContext>::Data: Send,695{696use tracing::Instrument;697let span = tracing::span!(698tracing::Level::TRACE, "wit-bindgen export", module =699"foo:foo/manyarg", function = "many-args",700);701let callee = unsafe {702wasmtime::component::TypedFunc::<703(704u64,705u64,706u64,707u64,708u64,709u64,710u64,711u64,712u64,713u64,714u64,715u64,716u64,717u64,718u64,719u64,720),721(),722>::new_unchecked(self.many_args)723};724let () = callee725.call_async(726store.as_context_mut(),727(728arg0,729arg1,730arg2,731arg3,732arg4,733arg5,734arg6,735arg7,736arg8,737arg9,738arg10,739arg11,740arg12,741arg13,742arg14,743arg15,744),745)746.instrument(span.clone())747.await?;748Ok(())749}750pub async fn call_big_argument<S: wasmtime::AsContextMut>(751&self,752mut store: S,753arg0: &BigStruct,754) -> wasmtime::Result<()>755where756<S as wasmtime::AsContext>::Data: Send,757{758use tracing::Instrument;759let span = tracing::span!(760tracing::Level::TRACE, "wit-bindgen export", module =761"foo:foo/manyarg", function = "big-argument",762);763let callee = unsafe {764wasmtime::component::TypedFunc::<765(&BigStruct,),766(),767>::new_unchecked(self.big_argument)768};769let () = callee770.call_async(store.as_context_mut(), (arg0,))771.instrument(span.clone())772.await?;773Ok(())774}775}776}777}778}779}780781782