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