Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/component-macro/tests/expanded/flags_tracing_async.rs
1692 views
1
/// Auto-generated bindings for a pre-instantiated version of a
2
/// component which implements the world `the-flags`.
3
///
4
/// This structure is created through [`TheFlagsPre::new`] which
5
/// takes a [`InstancePre`](wasmtime::component::InstancePre) that
6
/// has been created through a [`Linker`](wasmtime::component::Linker).
7
///
8
/// For more information see [`TheFlags`] as well.
9
pub struct TheFlagsPre<T: 'static> {
10
instance_pre: wasmtime::component::InstancePre<T>,
11
indices: TheFlagsIndices,
12
}
13
impl<T: 'static> Clone for TheFlagsPre<T> {
14
fn clone(&self) -> Self {
15
Self {
16
instance_pre: self.instance_pre.clone(),
17
indices: self.indices.clone(),
18
}
19
}
20
}
21
impl<_T: 'static> TheFlagsPre<_T> {
22
/// Creates a new copy of `TheFlagsPre` bindings which can then
23
/// be used to instantiate into a particular store.
24
///
25
/// This method may fail if the component behind `instance_pre`
26
/// does not have the required exports.
27
pub fn new(
28
instance_pre: wasmtime::component::InstancePre<_T>,
29
) -> wasmtime::Result<Self> {
30
let indices = TheFlagsIndices::new(&instance_pre)?;
31
Ok(Self { instance_pre, indices })
32
}
33
pub fn engine(&self) -> &wasmtime::Engine {
34
self.instance_pre.engine()
35
}
36
pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
37
&self.instance_pre
38
}
39
/// Instantiates a new instance of [`TheFlags`] within the
40
/// `store` provided.
41
///
42
/// This function will use `self` as the pre-instantiated
43
/// instance to perform instantiation. Afterwards the preloaded
44
/// indices in `self` are used to lookup all exports on the
45
/// resulting instance.
46
pub fn instantiate(
47
&self,
48
mut store: impl wasmtime::AsContextMut<Data = _T>,
49
) -> wasmtime::Result<TheFlags> {
50
let mut store = store.as_context_mut();
51
let instance = self.instance_pre.instantiate(&mut store)?;
52
self.indices.load(&mut store, &instance)
53
}
54
}
55
impl<_T: Send + 'static> TheFlagsPre<_T> {
56
/// Same as [`Self::instantiate`], except with `async`.
57
pub async fn instantiate_async(
58
&self,
59
mut store: impl wasmtime::AsContextMut<Data = _T>,
60
) -> wasmtime::Result<TheFlags> {
61
let mut store = store.as_context_mut();
62
let instance = self.instance_pre.instantiate_async(&mut store).await?;
63
self.indices.load(&mut store, &instance)
64
}
65
}
66
/// Auto-generated bindings for index of the exports of
67
/// `the-flags`.
68
///
69
/// This is an implementation detail of [`TheFlagsPre`] and can
70
/// be constructed if needed as well.
71
///
72
/// For more information see [`TheFlags`] as well.
73
#[derive(Clone)]
74
pub struct TheFlagsIndices {
75
interface0: exports::foo::foo::flegs::GuestIndices,
76
}
77
/// Auto-generated bindings for an instance a component which
78
/// implements the world `the-flags`.
79
///
80
/// This structure can be created through a number of means
81
/// depending on your requirements and what you have on hand:
82
///
83
/// * The most convenient way is to use
84
/// [`TheFlags::instantiate`] which only needs a
85
/// [`Store`], [`Component`], and [`Linker`].
86
///
87
/// * Alternatively you can create a [`TheFlagsPre`] ahead of
88
/// time with a [`Component`] to front-load string lookups
89
/// of exports once instead of per-instantiation. This
90
/// method then uses [`TheFlagsPre::instantiate`] to
91
/// create a [`TheFlags`].
92
///
93
/// * If you've instantiated the instance yourself already
94
/// then you can use [`TheFlags::new`].
95
///
96
/// These methods are all equivalent to one another and move
97
/// around the tradeoff of what work is performed when.
98
///
99
/// [`Store`]: wasmtime::Store
100
/// [`Component`]: wasmtime::component::Component
101
/// [`Linker`]: wasmtime::component::Linker
102
pub struct TheFlags {
103
interface0: exports::foo::foo::flegs::Guest,
104
}
105
const _: () = {
106
#[allow(unused_imports)]
107
use wasmtime::component::__internal::anyhow;
108
impl TheFlagsIndices {
109
/// Creates a new copy of `TheFlagsIndices` bindings which can then
110
/// be used to instantiate into a particular store.
111
///
112
/// This method may fail if the component does not have the
113
/// required exports.
114
pub fn new<_T>(
115
_instance_pre: &wasmtime::component::InstancePre<_T>,
116
) -> wasmtime::Result<Self> {
117
let _component = _instance_pre.component();
118
let _instance_type = _instance_pre.instance_type();
119
let interface0 = exports::foo::foo::flegs::GuestIndices::new(_instance_pre)?;
120
Ok(TheFlagsIndices { interface0 })
121
}
122
/// Uses the indices stored in `self` to load an instance
123
/// of [`TheFlags`] from the instance provided.
124
///
125
/// Note that at this time this method will additionally
126
/// perform type-checks of all exports.
127
pub fn load(
128
&self,
129
mut store: impl wasmtime::AsContextMut,
130
instance: &wasmtime::component::Instance,
131
) -> wasmtime::Result<TheFlags> {
132
let _ = &mut store;
133
let _instance = instance;
134
let interface0 = self.interface0.load(&mut store, &_instance)?;
135
Ok(TheFlags { interface0 })
136
}
137
}
138
impl TheFlags {
139
/// Convenience wrapper around [`TheFlagsPre::new`] and
140
/// [`TheFlagsPre::instantiate`].
141
pub fn instantiate<_T>(
142
store: impl wasmtime::AsContextMut<Data = _T>,
143
component: &wasmtime::component::Component,
144
linker: &wasmtime::component::Linker<_T>,
145
) -> wasmtime::Result<TheFlags> {
146
let pre = linker.instantiate_pre(component)?;
147
TheFlagsPre::new(pre)?.instantiate(store)
148
}
149
/// Convenience wrapper around [`TheFlagsIndices::new`] and
150
/// [`TheFlagsIndices::load`].
151
pub fn new(
152
mut store: impl wasmtime::AsContextMut,
153
instance: &wasmtime::component::Instance,
154
) -> wasmtime::Result<TheFlags> {
155
let indices = TheFlagsIndices::new(&instance.instance_pre(&store))?;
156
indices.load(&mut store, instance)
157
}
158
/// Convenience wrapper around [`TheFlagsPre::new`] and
159
/// [`TheFlagsPre::instantiate_async`].
160
pub async fn instantiate_async<_T>(
161
store: impl wasmtime::AsContextMut<Data = _T>,
162
component: &wasmtime::component::Component,
163
linker: &wasmtime::component::Linker<_T>,
164
) -> wasmtime::Result<TheFlags>
165
where
166
_T: Send,
167
{
168
let pre = linker.instantiate_pre(component)?;
169
TheFlagsPre::new(pre)?.instantiate_async(store).await
170
}
171
pub fn add_to_linker<T, D>(
172
linker: &mut wasmtime::component::Linker<T>,
173
host_getter: fn(&mut T) -> D::Data<'_>,
174
) -> wasmtime::Result<()>
175
where
176
D: foo::foo::flegs::HostWithStore + Send,
177
for<'a> D::Data<'a>: foo::foo::flegs::Host + Send,
178
T: 'static + Send,
179
{
180
foo::foo::flegs::add_to_linker::<T, D>(linker, host_getter)?;
181
Ok(())
182
}
183
pub fn foo_foo_flegs(&self) -> &exports::foo::foo::flegs::Guest {
184
&self.interface0
185
}
186
}
187
};
188
pub mod foo {
189
pub mod foo {
190
#[allow(clippy::all)]
191
pub mod flegs {
192
#[allow(unused_imports)]
193
use wasmtime::component::__internal::{anyhow, Box};
194
wasmtime::component::flags!(Flag1 { #[component(name = "b0")] const B0; });
195
const _: () = {
196
assert!(1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32);
197
assert!(1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32);
198
};
199
wasmtime::component::flags!(
200
Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]
201
const B1; }
202
);
203
const _: () = {
204
assert!(1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32);
205
assert!(1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32);
206
};
207
wasmtime::component::flags!(
208
Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]
209
const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]
210
const B3; }
211
);
212
const _: () = {
213
assert!(1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32);
214
assert!(1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32);
215
};
216
wasmtime::component::flags!(
217
Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]
218
const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]
219
const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]
220
const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]
221
const B7; }
222
);
223
const _: () = {
224
assert!(1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32);
225
assert!(1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32);
226
};
227
wasmtime::component::flags!(
228
Flag16 { #[component(name = "b0")] const B0; #[component(name = "b1")]
229
const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]
230
const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]
231
const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]
232
const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]
233
const B9; #[component(name = "b10")] const B10; #[component(name =
234
"b11")] const B11; #[component(name = "b12")] const B12; #[component(name
235
= "b13")] const B13; #[component(name = "b14")] const B14;
236
#[component(name = "b15")] const B15; }
237
);
238
const _: () = {
239
assert!(2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32);
240
assert!(2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32);
241
};
242
wasmtime::component::flags!(
243
Flag32 { #[component(name = "b0")] const B0; #[component(name = "b1")]
244
const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]
245
const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]
246
const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]
247
const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]
248
const B9; #[component(name = "b10")] const B10; #[component(name =
249
"b11")] const B11; #[component(name = "b12")] const B12; #[component(name
250
= "b13")] const B13; #[component(name = "b14")] const B14;
251
#[component(name = "b15")] const B15; #[component(name = "b16")] const
252
B16; #[component(name = "b17")] const B17; #[component(name = "b18")]
253
const B18; #[component(name = "b19")] const B19; #[component(name =
254
"b20")] const B20; #[component(name = "b21")] const B21; #[component(name
255
= "b22")] const B22; #[component(name = "b23")] const B23;
256
#[component(name = "b24")] const B24; #[component(name = "b25")] const
257
B25; #[component(name = "b26")] const B26; #[component(name = "b27")]
258
const B27; #[component(name = "b28")] const B28; #[component(name =
259
"b29")] const B29; #[component(name = "b30")] const B30; #[component(name
260
= "b31")] const B31; }
261
);
262
const _: () = {
263
assert!(4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32);
264
assert!(4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32);
265
};
266
wasmtime::component::flags!(
267
Flag64 { #[component(name = "b0")] const B0; #[component(name = "b1")]
268
const B1; #[component(name = "b2")] const B2; #[component(name = "b3")]
269
const B3; #[component(name = "b4")] const B4; #[component(name = "b5")]
270
const B5; #[component(name = "b6")] const B6; #[component(name = "b7")]
271
const B7; #[component(name = "b8")] const B8; #[component(name = "b9")]
272
const B9; #[component(name = "b10")] const B10; #[component(name =
273
"b11")] const B11; #[component(name = "b12")] const B12; #[component(name
274
= "b13")] const B13; #[component(name = "b14")] const B14;
275
#[component(name = "b15")] const B15; #[component(name = "b16")] const
276
B16; #[component(name = "b17")] const B17; #[component(name = "b18")]
277
const B18; #[component(name = "b19")] const B19; #[component(name =
278
"b20")] const B20; #[component(name = "b21")] const B21; #[component(name
279
= "b22")] const B22; #[component(name = "b23")] const B23;
280
#[component(name = "b24")] const B24; #[component(name = "b25")] const
281
B25; #[component(name = "b26")] const B26; #[component(name = "b27")]
282
const B27; #[component(name = "b28")] const B28; #[component(name =
283
"b29")] const B29; #[component(name = "b30")] const B30; #[component(name
284
= "b31")] const B31; #[component(name = "b32")] const B32;
285
#[component(name = "b33")] const B33; #[component(name = "b34")] const
286
B34; #[component(name = "b35")] const B35; #[component(name = "b36")]
287
const B36; #[component(name = "b37")] const B37; #[component(name =
288
"b38")] const B38; #[component(name = "b39")] const B39; #[component(name
289
= "b40")] const B40; #[component(name = "b41")] const B41;
290
#[component(name = "b42")] const B42; #[component(name = "b43")] const
291
B43; #[component(name = "b44")] const B44; #[component(name = "b45")]
292
const B45; #[component(name = "b46")] const B46; #[component(name =
293
"b47")] const B47; #[component(name = "b48")] const B48; #[component(name
294
= "b49")] const B49; #[component(name = "b50")] const B50;
295
#[component(name = "b51")] const B51; #[component(name = "b52")] const
296
B52; #[component(name = "b53")] const B53; #[component(name = "b54")]
297
const B54; #[component(name = "b55")] const B55; #[component(name =
298
"b56")] const B56; #[component(name = "b57")] const B57; #[component(name
299
= "b58")] const B58; #[component(name = "b59")] const B59;
300
#[component(name = "b60")] const B60; #[component(name = "b61")] const
301
B61; #[component(name = "b62")] const B62; #[component(name = "b63")]
302
const B63; }
303
);
304
const _: () = {
305
assert!(8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32);
306
assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32);
307
};
308
pub trait HostWithStore: wasmtime::component::HasData + Send {}
309
impl<_T: ?Sized> HostWithStore for _T
310
where
311
_T: wasmtime::component::HasData + Send,
312
{}
313
pub trait Host: Send {
314
fn roundtrip_flag1(
315
&mut self,
316
x: Flag1,
317
) -> impl ::core::future::Future<Output = Flag1> + Send;
318
fn roundtrip_flag2(
319
&mut self,
320
x: Flag2,
321
) -> impl ::core::future::Future<Output = Flag2> + Send;
322
fn roundtrip_flag4(
323
&mut self,
324
x: Flag4,
325
) -> impl ::core::future::Future<Output = Flag4> + Send;
326
fn roundtrip_flag8(
327
&mut self,
328
x: Flag8,
329
) -> impl ::core::future::Future<Output = Flag8> + Send;
330
fn roundtrip_flag16(
331
&mut self,
332
x: Flag16,
333
) -> impl ::core::future::Future<Output = Flag16> + Send;
334
fn roundtrip_flag32(
335
&mut self,
336
x: Flag32,
337
) -> impl ::core::future::Future<Output = Flag32> + Send;
338
fn roundtrip_flag64(
339
&mut self,
340
x: Flag64,
341
) -> impl ::core::future::Future<Output = Flag64> + Send;
342
}
343
impl<_T: Host + ?Sized + Send> Host for &mut _T {
344
fn roundtrip_flag1(
345
&mut self,
346
x: Flag1,
347
) -> impl ::core::future::Future<Output = Flag1> + Send {
348
async move { Host::roundtrip_flag1(*self, x).await }
349
}
350
fn roundtrip_flag2(
351
&mut self,
352
x: Flag2,
353
) -> impl ::core::future::Future<Output = Flag2> + Send {
354
async move { Host::roundtrip_flag2(*self, x).await }
355
}
356
fn roundtrip_flag4(
357
&mut self,
358
x: Flag4,
359
) -> impl ::core::future::Future<Output = Flag4> + Send {
360
async move { Host::roundtrip_flag4(*self, x).await }
361
}
362
fn roundtrip_flag8(
363
&mut self,
364
x: Flag8,
365
) -> impl ::core::future::Future<Output = Flag8> + Send {
366
async move { Host::roundtrip_flag8(*self, x).await }
367
}
368
fn roundtrip_flag16(
369
&mut self,
370
x: Flag16,
371
) -> impl ::core::future::Future<Output = Flag16> + Send {
372
async move { Host::roundtrip_flag16(*self, x).await }
373
}
374
fn roundtrip_flag32(
375
&mut self,
376
x: Flag32,
377
) -> impl ::core::future::Future<Output = Flag32> + Send {
378
async move { Host::roundtrip_flag32(*self, x).await }
379
}
380
fn roundtrip_flag64(
381
&mut self,
382
x: Flag64,
383
) -> impl ::core::future::Future<Output = Flag64> + Send {
384
async move { Host::roundtrip_flag64(*self, x).await }
385
}
386
}
387
pub fn add_to_linker<T, D>(
388
linker: &mut wasmtime::component::Linker<T>,
389
host_getter: fn(&mut T) -> D::Data<'_>,
390
) -> wasmtime::Result<()>
391
where
392
D: HostWithStore,
393
for<'a> D::Data<'a>: Host,
394
T: 'static + Send,
395
{
396
let mut inst = linker.instance("foo:foo/flegs")?;
397
inst.func_wrap_async(
398
"roundtrip-flag1",
399
move |
400
mut caller: wasmtime::StoreContextMut<'_, T>,
401
(arg0,): (Flag1,)|
402
{
403
use tracing::Instrument;
404
let span = tracing::span!(
405
tracing::Level::TRACE, "wit-bindgen import", module =
406
"flegs", function = "roundtrip-flag1",
407
);
408
wasmtime::component::__internal::Box::new(
409
async move {
410
tracing::event!(
411
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
412
"call"
413
);
414
let host = &mut host_getter(caller.data_mut());
415
let r = Host::roundtrip_flag1(host, arg0).await;
416
tracing::event!(
417
tracing::Level::TRACE, result = tracing::field::debug(& r),
418
"return"
419
);
420
Ok((r,))
421
}
422
.instrument(span),
423
)
424
},
425
)?;
426
inst.func_wrap_async(
427
"roundtrip-flag2",
428
move |
429
mut caller: wasmtime::StoreContextMut<'_, T>,
430
(arg0,): (Flag2,)|
431
{
432
use tracing::Instrument;
433
let span = tracing::span!(
434
tracing::Level::TRACE, "wit-bindgen import", module =
435
"flegs", function = "roundtrip-flag2",
436
);
437
wasmtime::component::__internal::Box::new(
438
async move {
439
tracing::event!(
440
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
441
"call"
442
);
443
let host = &mut host_getter(caller.data_mut());
444
let r = Host::roundtrip_flag2(host, arg0).await;
445
tracing::event!(
446
tracing::Level::TRACE, result = tracing::field::debug(& r),
447
"return"
448
);
449
Ok((r,))
450
}
451
.instrument(span),
452
)
453
},
454
)?;
455
inst.func_wrap_async(
456
"roundtrip-flag4",
457
move |
458
mut caller: wasmtime::StoreContextMut<'_, T>,
459
(arg0,): (Flag4,)|
460
{
461
use tracing::Instrument;
462
let span = tracing::span!(
463
tracing::Level::TRACE, "wit-bindgen import", module =
464
"flegs", function = "roundtrip-flag4",
465
);
466
wasmtime::component::__internal::Box::new(
467
async move {
468
tracing::event!(
469
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
470
"call"
471
);
472
let host = &mut host_getter(caller.data_mut());
473
let r = Host::roundtrip_flag4(host, arg0).await;
474
tracing::event!(
475
tracing::Level::TRACE, result = tracing::field::debug(& r),
476
"return"
477
);
478
Ok((r,))
479
}
480
.instrument(span),
481
)
482
},
483
)?;
484
inst.func_wrap_async(
485
"roundtrip-flag8",
486
move |
487
mut caller: wasmtime::StoreContextMut<'_, T>,
488
(arg0,): (Flag8,)|
489
{
490
use tracing::Instrument;
491
let span = tracing::span!(
492
tracing::Level::TRACE, "wit-bindgen import", module =
493
"flegs", function = "roundtrip-flag8",
494
);
495
wasmtime::component::__internal::Box::new(
496
async move {
497
tracing::event!(
498
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
499
"call"
500
);
501
let host = &mut host_getter(caller.data_mut());
502
let r = Host::roundtrip_flag8(host, arg0).await;
503
tracing::event!(
504
tracing::Level::TRACE, result = tracing::field::debug(& r),
505
"return"
506
);
507
Ok((r,))
508
}
509
.instrument(span),
510
)
511
},
512
)?;
513
inst.func_wrap_async(
514
"roundtrip-flag16",
515
move |
516
mut caller: wasmtime::StoreContextMut<'_, T>,
517
(arg0,): (Flag16,)|
518
{
519
use tracing::Instrument;
520
let span = tracing::span!(
521
tracing::Level::TRACE, "wit-bindgen import", module =
522
"flegs", function = "roundtrip-flag16",
523
);
524
wasmtime::component::__internal::Box::new(
525
async move {
526
tracing::event!(
527
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
528
"call"
529
);
530
let host = &mut host_getter(caller.data_mut());
531
let r = Host::roundtrip_flag16(host, arg0).await;
532
tracing::event!(
533
tracing::Level::TRACE, result = tracing::field::debug(& r),
534
"return"
535
);
536
Ok((r,))
537
}
538
.instrument(span),
539
)
540
},
541
)?;
542
inst.func_wrap_async(
543
"roundtrip-flag32",
544
move |
545
mut caller: wasmtime::StoreContextMut<'_, T>,
546
(arg0,): (Flag32,)|
547
{
548
use tracing::Instrument;
549
let span = tracing::span!(
550
tracing::Level::TRACE, "wit-bindgen import", module =
551
"flegs", function = "roundtrip-flag32",
552
);
553
wasmtime::component::__internal::Box::new(
554
async move {
555
tracing::event!(
556
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
557
"call"
558
);
559
let host = &mut host_getter(caller.data_mut());
560
let r = Host::roundtrip_flag32(host, arg0).await;
561
tracing::event!(
562
tracing::Level::TRACE, result = tracing::field::debug(& r),
563
"return"
564
);
565
Ok((r,))
566
}
567
.instrument(span),
568
)
569
},
570
)?;
571
inst.func_wrap_async(
572
"roundtrip-flag64",
573
move |
574
mut caller: wasmtime::StoreContextMut<'_, T>,
575
(arg0,): (Flag64,)|
576
{
577
use tracing::Instrument;
578
let span = tracing::span!(
579
tracing::Level::TRACE, "wit-bindgen import", module =
580
"flegs", function = "roundtrip-flag64",
581
);
582
wasmtime::component::__internal::Box::new(
583
async move {
584
tracing::event!(
585
tracing::Level::TRACE, x = tracing::field::debug(& arg0),
586
"call"
587
);
588
let host = &mut host_getter(caller.data_mut());
589
let r = Host::roundtrip_flag64(host, arg0).await;
590
tracing::event!(
591
tracing::Level::TRACE, result = tracing::field::debug(& r),
592
"return"
593
);
594
Ok((r,))
595
}
596
.instrument(span),
597
)
598
},
599
)?;
600
Ok(())
601
}
602
}
603
}
604
}
605
pub mod exports {
606
pub mod foo {
607
pub mod foo {
608
#[allow(clippy::all)]
609
pub mod flegs {
610
#[allow(unused_imports)]
611
use wasmtime::component::__internal::{anyhow, Box};
612
wasmtime::component::flags!(
613
Flag1 { #[component(name = "b0")] const B0; }
614
);
615
const _: () = {
616
assert!(
617
1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32
618
);
619
assert!(
620
1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32
621
);
622
};
623
wasmtime::component::flags!(
624
Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]
625
const B1; }
626
);
627
const _: () = {
628
assert!(
629
1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32
630
);
631
assert!(
632
1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32
633
);
634
};
635
wasmtime::component::flags!(
636
Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]
637
const B1; #[component(name = "b2")] const B2; #[component(name =
638
"b3")] const B3; }
639
);
640
const _: () = {
641
assert!(
642
1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32
643
);
644
assert!(
645
1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32
646
);
647
};
648
wasmtime::component::flags!(
649
Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]
650
const B1; #[component(name = "b2")] const B2; #[component(name =
651
"b3")] const B3; #[component(name = "b4")] const B4; #[component(name
652
= "b5")] const B5; #[component(name = "b6")] const B6;
653
#[component(name = "b7")] const B7; }
654
);
655
const _: () = {
656
assert!(
657
1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32
658
);
659
assert!(
660
1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32
661
);
662
};
663
wasmtime::component::flags!(
664
Flag16 { #[component(name = "b0")] const B0; #[component(name =
665
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
666
= "b3")] const B3; #[component(name = "b4")] const B4;
667
#[component(name = "b5")] const B5; #[component(name = "b6")] const
668
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
669
const B8; #[component(name = "b9")] const B9; #[component(name =
670
"b10")] const B10; #[component(name = "b11")] const B11;
671
#[component(name = "b12")] const B12; #[component(name = "b13")]
672
const B13; #[component(name = "b14")] const B14; #[component(name =
673
"b15")] const B15; }
674
);
675
const _: () = {
676
assert!(
677
2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32
678
);
679
assert!(
680
2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32
681
);
682
};
683
wasmtime::component::flags!(
684
Flag32 { #[component(name = "b0")] const B0; #[component(name =
685
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
686
= "b3")] const B3; #[component(name = "b4")] const B4;
687
#[component(name = "b5")] const B5; #[component(name = "b6")] const
688
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
689
const B8; #[component(name = "b9")] const B9; #[component(name =
690
"b10")] const B10; #[component(name = "b11")] const B11;
691
#[component(name = "b12")] const B12; #[component(name = "b13")]
692
const B13; #[component(name = "b14")] const B14; #[component(name =
693
"b15")] const B15; #[component(name = "b16")] const B16;
694
#[component(name = "b17")] const B17; #[component(name = "b18")]
695
const B18; #[component(name = "b19")] const B19; #[component(name =
696
"b20")] const B20; #[component(name = "b21")] const B21;
697
#[component(name = "b22")] const B22; #[component(name = "b23")]
698
const B23; #[component(name = "b24")] const B24; #[component(name =
699
"b25")] const B25; #[component(name = "b26")] const B26;
700
#[component(name = "b27")] const B27; #[component(name = "b28")]
701
const B28; #[component(name = "b29")] const B29; #[component(name =
702
"b30")] const B30; #[component(name = "b31")] const B31; }
703
);
704
const _: () = {
705
assert!(
706
4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32
707
);
708
assert!(
709
4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32
710
);
711
};
712
wasmtime::component::flags!(
713
Flag64 { #[component(name = "b0")] const B0; #[component(name =
714
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
715
= "b3")] const B3; #[component(name = "b4")] const B4;
716
#[component(name = "b5")] const B5; #[component(name = "b6")] const
717
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
718
const B8; #[component(name = "b9")] const B9; #[component(name =
719
"b10")] const B10; #[component(name = "b11")] const B11;
720
#[component(name = "b12")] const B12; #[component(name = "b13")]
721
const B13; #[component(name = "b14")] const B14; #[component(name =
722
"b15")] const B15; #[component(name = "b16")] const B16;
723
#[component(name = "b17")] const B17; #[component(name = "b18")]
724
const B18; #[component(name = "b19")] const B19; #[component(name =
725
"b20")] const B20; #[component(name = "b21")] const B21;
726
#[component(name = "b22")] const B22; #[component(name = "b23")]
727
const B23; #[component(name = "b24")] const B24; #[component(name =
728
"b25")] const B25; #[component(name = "b26")] const B26;
729
#[component(name = "b27")] const B27; #[component(name = "b28")]
730
const B28; #[component(name = "b29")] const B29; #[component(name =
731
"b30")] const B30; #[component(name = "b31")] const B31;
732
#[component(name = "b32")] const B32; #[component(name = "b33")]
733
const B33; #[component(name = "b34")] const B34; #[component(name =
734
"b35")] const B35; #[component(name = "b36")] const B36;
735
#[component(name = "b37")] const B37; #[component(name = "b38")]
736
const B38; #[component(name = "b39")] const B39; #[component(name =
737
"b40")] const B40; #[component(name = "b41")] const B41;
738
#[component(name = "b42")] const B42; #[component(name = "b43")]
739
const B43; #[component(name = "b44")] const B44; #[component(name =
740
"b45")] const B45; #[component(name = "b46")] const B46;
741
#[component(name = "b47")] const B47; #[component(name = "b48")]
742
const B48; #[component(name = "b49")] const B49; #[component(name =
743
"b50")] const B50; #[component(name = "b51")] const B51;
744
#[component(name = "b52")] const B52; #[component(name = "b53")]
745
const B53; #[component(name = "b54")] const B54; #[component(name =
746
"b55")] const B55; #[component(name = "b56")] const B56;
747
#[component(name = "b57")] const B57; #[component(name = "b58")]
748
const B58; #[component(name = "b59")] const B59; #[component(name =
749
"b60")] const B60; #[component(name = "b61")] const B61;
750
#[component(name = "b62")] const B62; #[component(name = "b63")]
751
const B63; }
752
);
753
const _: () = {
754
assert!(
755
8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32
756
);
757
assert!(
758
4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32
759
);
760
};
761
pub struct Guest {
762
roundtrip_flag1: wasmtime::component::Func,
763
roundtrip_flag2: wasmtime::component::Func,
764
roundtrip_flag4: wasmtime::component::Func,
765
roundtrip_flag8: wasmtime::component::Func,
766
roundtrip_flag16: wasmtime::component::Func,
767
roundtrip_flag32: wasmtime::component::Func,
768
roundtrip_flag64: wasmtime::component::Func,
769
}
770
#[derive(Clone)]
771
pub struct GuestIndices {
772
roundtrip_flag1: wasmtime::component::ComponentExportIndex,
773
roundtrip_flag2: wasmtime::component::ComponentExportIndex,
774
roundtrip_flag4: wasmtime::component::ComponentExportIndex,
775
roundtrip_flag8: wasmtime::component::ComponentExportIndex,
776
roundtrip_flag16: wasmtime::component::ComponentExportIndex,
777
roundtrip_flag32: wasmtime::component::ComponentExportIndex,
778
roundtrip_flag64: wasmtime::component::ComponentExportIndex,
779
}
780
impl GuestIndices {
781
/// Constructor for [`GuestIndices`] which takes a
782
/// [`Component`](wasmtime::component::Component) as input and can be executed
783
/// before instantiation.
784
///
785
/// This constructor can be used to front-load string lookups to find exports
786
/// within a component.
787
pub fn new<_T>(
788
_instance_pre: &wasmtime::component::InstancePre<_T>,
789
) -> wasmtime::Result<GuestIndices> {
790
let instance = _instance_pre
791
.component()
792
.get_export_index(None, "foo:foo/flegs")
793
.ok_or_else(|| {
794
anyhow::anyhow!(
795
"no exported instance named `foo:foo/flegs`"
796
)
797
})?;
798
let mut lookup = move |name| {
799
_instance_pre
800
.component()
801
.get_export_index(Some(&instance), name)
802
.ok_or_else(|| {
803
anyhow::anyhow!(
804
"instance export `foo:foo/flegs` does \
805
not have export `{name}`"
806
)
807
})
808
};
809
let _ = &mut lookup;
810
let roundtrip_flag1 = lookup("roundtrip-flag1")?;
811
let roundtrip_flag2 = lookup("roundtrip-flag2")?;
812
let roundtrip_flag4 = lookup("roundtrip-flag4")?;
813
let roundtrip_flag8 = lookup("roundtrip-flag8")?;
814
let roundtrip_flag16 = lookup("roundtrip-flag16")?;
815
let roundtrip_flag32 = lookup("roundtrip-flag32")?;
816
let roundtrip_flag64 = lookup("roundtrip-flag64")?;
817
Ok(GuestIndices {
818
roundtrip_flag1,
819
roundtrip_flag2,
820
roundtrip_flag4,
821
roundtrip_flag8,
822
roundtrip_flag16,
823
roundtrip_flag32,
824
roundtrip_flag64,
825
})
826
}
827
pub fn load(
828
&self,
829
mut store: impl wasmtime::AsContextMut,
830
instance: &wasmtime::component::Instance,
831
) -> wasmtime::Result<Guest> {
832
let _instance = instance;
833
let _instance_pre = _instance.instance_pre(&store);
834
let _instance_type = _instance_pre.instance_type();
835
let mut store = store.as_context_mut();
836
let _ = &mut store;
837
let roundtrip_flag1 = *_instance
838
.get_typed_func::<
839
(Flag1,),
840
(Flag1,),
841
>(&mut store, &self.roundtrip_flag1)?
842
.func();
843
let roundtrip_flag2 = *_instance
844
.get_typed_func::<
845
(Flag2,),
846
(Flag2,),
847
>(&mut store, &self.roundtrip_flag2)?
848
.func();
849
let roundtrip_flag4 = *_instance
850
.get_typed_func::<
851
(Flag4,),
852
(Flag4,),
853
>(&mut store, &self.roundtrip_flag4)?
854
.func();
855
let roundtrip_flag8 = *_instance
856
.get_typed_func::<
857
(Flag8,),
858
(Flag8,),
859
>(&mut store, &self.roundtrip_flag8)?
860
.func();
861
let roundtrip_flag16 = *_instance
862
.get_typed_func::<
863
(Flag16,),
864
(Flag16,),
865
>(&mut store, &self.roundtrip_flag16)?
866
.func();
867
let roundtrip_flag32 = *_instance
868
.get_typed_func::<
869
(Flag32,),
870
(Flag32,),
871
>(&mut store, &self.roundtrip_flag32)?
872
.func();
873
let roundtrip_flag64 = *_instance
874
.get_typed_func::<
875
(Flag64,),
876
(Flag64,),
877
>(&mut store, &self.roundtrip_flag64)?
878
.func();
879
Ok(Guest {
880
roundtrip_flag1,
881
roundtrip_flag2,
882
roundtrip_flag4,
883
roundtrip_flag8,
884
roundtrip_flag16,
885
roundtrip_flag32,
886
roundtrip_flag64,
887
})
888
}
889
}
890
impl Guest {
891
pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(
892
&self,
893
mut store: S,
894
arg0: Flag1,
895
) -> wasmtime::Result<Flag1>
896
where
897
<S as wasmtime::AsContext>::Data: Send,
898
{
899
use tracing::Instrument;
900
let span = tracing::span!(
901
tracing::Level::TRACE, "wit-bindgen export", module =
902
"foo:foo/flegs", function = "roundtrip-flag1",
903
);
904
let callee = unsafe {
905
wasmtime::component::TypedFunc::<
906
(Flag1,),
907
(Flag1,),
908
>::new_unchecked(self.roundtrip_flag1)
909
};
910
let (ret0,) = callee
911
.call_async(store.as_context_mut(), (arg0,))
912
.instrument(span.clone())
913
.await?;
914
callee
915
.post_return_async(store.as_context_mut())
916
.instrument(span)
917
.await?;
918
Ok(ret0)
919
}
920
pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(
921
&self,
922
mut store: S,
923
arg0: Flag2,
924
) -> wasmtime::Result<Flag2>
925
where
926
<S as wasmtime::AsContext>::Data: Send,
927
{
928
use tracing::Instrument;
929
let span = tracing::span!(
930
tracing::Level::TRACE, "wit-bindgen export", module =
931
"foo:foo/flegs", function = "roundtrip-flag2",
932
);
933
let callee = unsafe {
934
wasmtime::component::TypedFunc::<
935
(Flag2,),
936
(Flag2,),
937
>::new_unchecked(self.roundtrip_flag2)
938
};
939
let (ret0,) = callee
940
.call_async(store.as_context_mut(), (arg0,))
941
.instrument(span.clone())
942
.await?;
943
callee
944
.post_return_async(store.as_context_mut())
945
.instrument(span)
946
.await?;
947
Ok(ret0)
948
}
949
pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(
950
&self,
951
mut store: S,
952
arg0: Flag4,
953
) -> wasmtime::Result<Flag4>
954
where
955
<S as wasmtime::AsContext>::Data: Send,
956
{
957
use tracing::Instrument;
958
let span = tracing::span!(
959
tracing::Level::TRACE, "wit-bindgen export", module =
960
"foo:foo/flegs", function = "roundtrip-flag4",
961
);
962
let callee = unsafe {
963
wasmtime::component::TypedFunc::<
964
(Flag4,),
965
(Flag4,),
966
>::new_unchecked(self.roundtrip_flag4)
967
};
968
let (ret0,) = callee
969
.call_async(store.as_context_mut(), (arg0,))
970
.instrument(span.clone())
971
.await?;
972
callee
973
.post_return_async(store.as_context_mut())
974
.instrument(span)
975
.await?;
976
Ok(ret0)
977
}
978
pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(
979
&self,
980
mut store: S,
981
arg0: Flag8,
982
) -> wasmtime::Result<Flag8>
983
where
984
<S as wasmtime::AsContext>::Data: Send,
985
{
986
use tracing::Instrument;
987
let span = tracing::span!(
988
tracing::Level::TRACE, "wit-bindgen export", module =
989
"foo:foo/flegs", function = "roundtrip-flag8",
990
);
991
let callee = unsafe {
992
wasmtime::component::TypedFunc::<
993
(Flag8,),
994
(Flag8,),
995
>::new_unchecked(self.roundtrip_flag8)
996
};
997
let (ret0,) = callee
998
.call_async(store.as_context_mut(), (arg0,))
999
.instrument(span.clone())
1000
.await?;
1001
callee
1002
.post_return_async(store.as_context_mut())
1003
.instrument(span)
1004
.await?;
1005
Ok(ret0)
1006
}
1007
pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(
1008
&self,
1009
mut store: S,
1010
arg0: Flag16,
1011
) -> wasmtime::Result<Flag16>
1012
where
1013
<S as wasmtime::AsContext>::Data: Send,
1014
{
1015
use tracing::Instrument;
1016
let span = tracing::span!(
1017
tracing::Level::TRACE, "wit-bindgen export", module =
1018
"foo:foo/flegs", function = "roundtrip-flag16",
1019
);
1020
let callee = unsafe {
1021
wasmtime::component::TypedFunc::<
1022
(Flag16,),
1023
(Flag16,),
1024
>::new_unchecked(self.roundtrip_flag16)
1025
};
1026
let (ret0,) = callee
1027
.call_async(store.as_context_mut(), (arg0,))
1028
.instrument(span.clone())
1029
.await?;
1030
callee
1031
.post_return_async(store.as_context_mut())
1032
.instrument(span)
1033
.await?;
1034
Ok(ret0)
1035
}
1036
pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(
1037
&self,
1038
mut store: S,
1039
arg0: Flag32,
1040
) -> wasmtime::Result<Flag32>
1041
where
1042
<S as wasmtime::AsContext>::Data: Send,
1043
{
1044
use tracing::Instrument;
1045
let span = tracing::span!(
1046
tracing::Level::TRACE, "wit-bindgen export", module =
1047
"foo:foo/flegs", function = "roundtrip-flag32",
1048
);
1049
let callee = unsafe {
1050
wasmtime::component::TypedFunc::<
1051
(Flag32,),
1052
(Flag32,),
1053
>::new_unchecked(self.roundtrip_flag32)
1054
};
1055
let (ret0,) = callee
1056
.call_async(store.as_context_mut(), (arg0,))
1057
.instrument(span.clone())
1058
.await?;
1059
callee
1060
.post_return_async(store.as_context_mut())
1061
.instrument(span)
1062
.await?;
1063
Ok(ret0)
1064
}
1065
pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(
1066
&self,
1067
mut store: S,
1068
arg0: Flag64,
1069
) -> wasmtime::Result<Flag64>
1070
where
1071
<S as wasmtime::AsContext>::Data: Send,
1072
{
1073
use tracing::Instrument;
1074
let span = tracing::span!(
1075
tracing::Level::TRACE, "wit-bindgen export", module =
1076
"foo:foo/flegs", function = "roundtrip-flag64",
1077
);
1078
let callee = unsafe {
1079
wasmtime::component::TypedFunc::<
1080
(Flag64,),
1081
(Flag64,),
1082
>::new_unchecked(self.roundtrip_flag64)
1083
};
1084
let (ret0,) = callee
1085
.call_async(store.as_context_mut(), (arg0,))
1086
.instrument(span.clone())
1087
.await?;
1088
callee
1089
.post_return_async(store.as_context_mut())
1090
.instrument(span)
1091
.await?;
1092
Ok(ret0)
1093
}
1094
}
1095
}
1096
}
1097
}
1098
}
1099
1100