Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/component-macro/tests/expanded/flags_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
wasmtime::component::__internal::Box::new(async move {
404
let host = &mut host_getter(caller.data_mut());
405
let r = Host::roundtrip_flag1(host, arg0).await;
406
Ok((r,))
407
})
408
},
409
)?;
410
inst.func_wrap_async(
411
"roundtrip-flag2",
412
move |
413
mut caller: wasmtime::StoreContextMut<'_, T>,
414
(arg0,): (Flag2,)|
415
{
416
wasmtime::component::__internal::Box::new(async move {
417
let host = &mut host_getter(caller.data_mut());
418
let r = Host::roundtrip_flag2(host, arg0).await;
419
Ok((r,))
420
})
421
},
422
)?;
423
inst.func_wrap_async(
424
"roundtrip-flag4",
425
move |
426
mut caller: wasmtime::StoreContextMut<'_, T>,
427
(arg0,): (Flag4,)|
428
{
429
wasmtime::component::__internal::Box::new(async move {
430
let host = &mut host_getter(caller.data_mut());
431
let r = Host::roundtrip_flag4(host, arg0).await;
432
Ok((r,))
433
})
434
},
435
)?;
436
inst.func_wrap_async(
437
"roundtrip-flag8",
438
move |
439
mut caller: wasmtime::StoreContextMut<'_, T>,
440
(arg0,): (Flag8,)|
441
{
442
wasmtime::component::__internal::Box::new(async move {
443
let host = &mut host_getter(caller.data_mut());
444
let r = Host::roundtrip_flag8(host, arg0).await;
445
Ok((r,))
446
})
447
},
448
)?;
449
inst.func_wrap_async(
450
"roundtrip-flag16",
451
move |
452
mut caller: wasmtime::StoreContextMut<'_, T>,
453
(arg0,): (Flag16,)|
454
{
455
wasmtime::component::__internal::Box::new(async move {
456
let host = &mut host_getter(caller.data_mut());
457
let r = Host::roundtrip_flag16(host, arg0).await;
458
Ok((r,))
459
})
460
},
461
)?;
462
inst.func_wrap_async(
463
"roundtrip-flag32",
464
move |
465
mut caller: wasmtime::StoreContextMut<'_, T>,
466
(arg0,): (Flag32,)|
467
{
468
wasmtime::component::__internal::Box::new(async move {
469
let host = &mut host_getter(caller.data_mut());
470
let r = Host::roundtrip_flag32(host, arg0).await;
471
Ok((r,))
472
})
473
},
474
)?;
475
inst.func_wrap_async(
476
"roundtrip-flag64",
477
move |
478
mut caller: wasmtime::StoreContextMut<'_, T>,
479
(arg0,): (Flag64,)|
480
{
481
wasmtime::component::__internal::Box::new(async move {
482
let host = &mut host_getter(caller.data_mut());
483
let r = Host::roundtrip_flag64(host, arg0).await;
484
Ok((r,))
485
})
486
},
487
)?;
488
Ok(())
489
}
490
}
491
}
492
}
493
pub mod exports {
494
pub mod foo {
495
pub mod foo {
496
#[allow(clippy::all)]
497
pub mod flegs {
498
#[allow(unused_imports)]
499
use wasmtime::component::__internal::{anyhow, Box};
500
wasmtime::component::flags!(
501
Flag1 { #[component(name = "b0")] const B0; }
502
);
503
const _: () = {
504
assert!(
505
1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32
506
);
507
assert!(
508
1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32
509
);
510
};
511
wasmtime::component::flags!(
512
Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]
513
const B1; }
514
);
515
const _: () = {
516
assert!(
517
1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32
518
);
519
assert!(
520
1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32
521
);
522
};
523
wasmtime::component::flags!(
524
Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]
525
const B1; #[component(name = "b2")] const B2; #[component(name =
526
"b3")] const B3; }
527
);
528
const _: () = {
529
assert!(
530
1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32
531
);
532
assert!(
533
1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32
534
);
535
};
536
wasmtime::component::flags!(
537
Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]
538
const B1; #[component(name = "b2")] const B2; #[component(name =
539
"b3")] const B3; #[component(name = "b4")] const B4; #[component(name
540
= "b5")] const B5; #[component(name = "b6")] const B6;
541
#[component(name = "b7")] const B7; }
542
);
543
const _: () = {
544
assert!(
545
1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32
546
);
547
assert!(
548
1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32
549
);
550
};
551
wasmtime::component::flags!(
552
Flag16 { #[component(name = "b0")] const B0; #[component(name =
553
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
554
= "b3")] const B3; #[component(name = "b4")] const B4;
555
#[component(name = "b5")] const B5; #[component(name = "b6")] const
556
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
557
const B8; #[component(name = "b9")] const B9; #[component(name =
558
"b10")] const B10; #[component(name = "b11")] const B11;
559
#[component(name = "b12")] const B12; #[component(name = "b13")]
560
const B13; #[component(name = "b14")] const B14; #[component(name =
561
"b15")] const B15; }
562
);
563
const _: () = {
564
assert!(
565
2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32
566
);
567
assert!(
568
2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32
569
);
570
};
571
wasmtime::component::flags!(
572
Flag32 { #[component(name = "b0")] const B0; #[component(name =
573
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
574
= "b3")] const B3; #[component(name = "b4")] const B4;
575
#[component(name = "b5")] const B5; #[component(name = "b6")] const
576
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
577
const B8; #[component(name = "b9")] const B9; #[component(name =
578
"b10")] const B10; #[component(name = "b11")] const B11;
579
#[component(name = "b12")] const B12; #[component(name = "b13")]
580
const B13; #[component(name = "b14")] const B14; #[component(name =
581
"b15")] const B15; #[component(name = "b16")] const B16;
582
#[component(name = "b17")] const B17; #[component(name = "b18")]
583
const B18; #[component(name = "b19")] const B19; #[component(name =
584
"b20")] const B20; #[component(name = "b21")] const B21;
585
#[component(name = "b22")] const B22; #[component(name = "b23")]
586
const B23; #[component(name = "b24")] const B24; #[component(name =
587
"b25")] const B25; #[component(name = "b26")] const B26;
588
#[component(name = "b27")] const B27; #[component(name = "b28")]
589
const B28; #[component(name = "b29")] const B29; #[component(name =
590
"b30")] const B30; #[component(name = "b31")] const B31; }
591
);
592
const _: () = {
593
assert!(
594
4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32
595
);
596
assert!(
597
4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32
598
);
599
};
600
wasmtime::component::flags!(
601
Flag64 { #[component(name = "b0")] const B0; #[component(name =
602
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
603
= "b3")] const B3; #[component(name = "b4")] const B4;
604
#[component(name = "b5")] const B5; #[component(name = "b6")] const
605
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
606
const B8; #[component(name = "b9")] const B9; #[component(name =
607
"b10")] const B10; #[component(name = "b11")] const B11;
608
#[component(name = "b12")] const B12; #[component(name = "b13")]
609
const B13; #[component(name = "b14")] const B14; #[component(name =
610
"b15")] const B15; #[component(name = "b16")] const B16;
611
#[component(name = "b17")] const B17; #[component(name = "b18")]
612
const B18; #[component(name = "b19")] const B19; #[component(name =
613
"b20")] const B20; #[component(name = "b21")] const B21;
614
#[component(name = "b22")] const B22; #[component(name = "b23")]
615
const B23; #[component(name = "b24")] const B24; #[component(name =
616
"b25")] const B25; #[component(name = "b26")] const B26;
617
#[component(name = "b27")] const B27; #[component(name = "b28")]
618
const B28; #[component(name = "b29")] const B29; #[component(name =
619
"b30")] const B30; #[component(name = "b31")] const B31;
620
#[component(name = "b32")] const B32; #[component(name = "b33")]
621
const B33; #[component(name = "b34")] const B34; #[component(name =
622
"b35")] const B35; #[component(name = "b36")] const B36;
623
#[component(name = "b37")] const B37; #[component(name = "b38")]
624
const B38; #[component(name = "b39")] const B39; #[component(name =
625
"b40")] const B40; #[component(name = "b41")] const B41;
626
#[component(name = "b42")] const B42; #[component(name = "b43")]
627
const B43; #[component(name = "b44")] const B44; #[component(name =
628
"b45")] const B45; #[component(name = "b46")] const B46;
629
#[component(name = "b47")] const B47; #[component(name = "b48")]
630
const B48; #[component(name = "b49")] const B49; #[component(name =
631
"b50")] const B50; #[component(name = "b51")] const B51;
632
#[component(name = "b52")] const B52; #[component(name = "b53")]
633
const B53; #[component(name = "b54")] const B54; #[component(name =
634
"b55")] const B55; #[component(name = "b56")] const B56;
635
#[component(name = "b57")] const B57; #[component(name = "b58")]
636
const B58; #[component(name = "b59")] const B59; #[component(name =
637
"b60")] const B60; #[component(name = "b61")] const B61;
638
#[component(name = "b62")] const B62; #[component(name = "b63")]
639
const B63; }
640
);
641
const _: () = {
642
assert!(
643
8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32
644
);
645
assert!(
646
4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32
647
);
648
};
649
pub struct Guest {
650
roundtrip_flag1: wasmtime::component::Func,
651
roundtrip_flag2: wasmtime::component::Func,
652
roundtrip_flag4: wasmtime::component::Func,
653
roundtrip_flag8: wasmtime::component::Func,
654
roundtrip_flag16: wasmtime::component::Func,
655
roundtrip_flag32: wasmtime::component::Func,
656
roundtrip_flag64: wasmtime::component::Func,
657
}
658
#[derive(Clone)]
659
pub struct GuestIndices {
660
roundtrip_flag1: wasmtime::component::ComponentExportIndex,
661
roundtrip_flag2: wasmtime::component::ComponentExportIndex,
662
roundtrip_flag4: wasmtime::component::ComponentExportIndex,
663
roundtrip_flag8: wasmtime::component::ComponentExportIndex,
664
roundtrip_flag16: wasmtime::component::ComponentExportIndex,
665
roundtrip_flag32: wasmtime::component::ComponentExportIndex,
666
roundtrip_flag64: wasmtime::component::ComponentExportIndex,
667
}
668
impl GuestIndices {
669
/// Constructor for [`GuestIndices`] which takes a
670
/// [`Component`](wasmtime::component::Component) as input and can be executed
671
/// before instantiation.
672
///
673
/// This constructor can be used to front-load string lookups to find exports
674
/// within a component.
675
pub fn new<_T>(
676
_instance_pre: &wasmtime::component::InstancePre<_T>,
677
) -> wasmtime::Result<GuestIndices> {
678
let instance = _instance_pre
679
.component()
680
.get_export_index(None, "foo:foo/flegs")
681
.ok_or_else(|| {
682
anyhow::anyhow!(
683
"no exported instance named `foo:foo/flegs`"
684
)
685
})?;
686
let mut lookup = move |name| {
687
_instance_pre
688
.component()
689
.get_export_index(Some(&instance), name)
690
.ok_or_else(|| {
691
anyhow::anyhow!(
692
"instance export `foo:foo/flegs` does \
693
not have export `{name}`"
694
)
695
})
696
};
697
let _ = &mut lookup;
698
let roundtrip_flag1 = lookup("roundtrip-flag1")?;
699
let roundtrip_flag2 = lookup("roundtrip-flag2")?;
700
let roundtrip_flag4 = lookup("roundtrip-flag4")?;
701
let roundtrip_flag8 = lookup("roundtrip-flag8")?;
702
let roundtrip_flag16 = lookup("roundtrip-flag16")?;
703
let roundtrip_flag32 = lookup("roundtrip-flag32")?;
704
let roundtrip_flag64 = lookup("roundtrip-flag64")?;
705
Ok(GuestIndices {
706
roundtrip_flag1,
707
roundtrip_flag2,
708
roundtrip_flag4,
709
roundtrip_flag8,
710
roundtrip_flag16,
711
roundtrip_flag32,
712
roundtrip_flag64,
713
})
714
}
715
pub fn load(
716
&self,
717
mut store: impl wasmtime::AsContextMut,
718
instance: &wasmtime::component::Instance,
719
) -> wasmtime::Result<Guest> {
720
let _instance = instance;
721
let _instance_pre = _instance.instance_pre(&store);
722
let _instance_type = _instance_pre.instance_type();
723
let mut store = store.as_context_mut();
724
let _ = &mut store;
725
let roundtrip_flag1 = *_instance
726
.get_typed_func::<
727
(Flag1,),
728
(Flag1,),
729
>(&mut store, &self.roundtrip_flag1)?
730
.func();
731
let roundtrip_flag2 = *_instance
732
.get_typed_func::<
733
(Flag2,),
734
(Flag2,),
735
>(&mut store, &self.roundtrip_flag2)?
736
.func();
737
let roundtrip_flag4 = *_instance
738
.get_typed_func::<
739
(Flag4,),
740
(Flag4,),
741
>(&mut store, &self.roundtrip_flag4)?
742
.func();
743
let roundtrip_flag8 = *_instance
744
.get_typed_func::<
745
(Flag8,),
746
(Flag8,),
747
>(&mut store, &self.roundtrip_flag8)?
748
.func();
749
let roundtrip_flag16 = *_instance
750
.get_typed_func::<
751
(Flag16,),
752
(Flag16,),
753
>(&mut store, &self.roundtrip_flag16)?
754
.func();
755
let roundtrip_flag32 = *_instance
756
.get_typed_func::<
757
(Flag32,),
758
(Flag32,),
759
>(&mut store, &self.roundtrip_flag32)?
760
.func();
761
let roundtrip_flag64 = *_instance
762
.get_typed_func::<
763
(Flag64,),
764
(Flag64,),
765
>(&mut store, &self.roundtrip_flag64)?
766
.func();
767
Ok(Guest {
768
roundtrip_flag1,
769
roundtrip_flag2,
770
roundtrip_flag4,
771
roundtrip_flag8,
772
roundtrip_flag16,
773
roundtrip_flag32,
774
roundtrip_flag64,
775
})
776
}
777
}
778
impl Guest {
779
pub async fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(
780
&self,
781
mut store: S,
782
arg0: Flag1,
783
) -> wasmtime::Result<Flag1>
784
where
785
<S as wasmtime::AsContext>::Data: Send,
786
{
787
let callee = unsafe {
788
wasmtime::component::TypedFunc::<
789
(Flag1,),
790
(Flag1,),
791
>::new_unchecked(self.roundtrip_flag1)
792
};
793
let (ret0,) = callee
794
.call_async(store.as_context_mut(), (arg0,))
795
.await?;
796
callee.post_return_async(store.as_context_mut()).await?;
797
Ok(ret0)
798
}
799
pub async fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(
800
&self,
801
mut store: S,
802
arg0: Flag2,
803
) -> wasmtime::Result<Flag2>
804
where
805
<S as wasmtime::AsContext>::Data: Send,
806
{
807
let callee = unsafe {
808
wasmtime::component::TypedFunc::<
809
(Flag2,),
810
(Flag2,),
811
>::new_unchecked(self.roundtrip_flag2)
812
};
813
let (ret0,) = callee
814
.call_async(store.as_context_mut(), (arg0,))
815
.await?;
816
callee.post_return_async(store.as_context_mut()).await?;
817
Ok(ret0)
818
}
819
pub async fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(
820
&self,
821
mut store: S,
822
arg0: Flag4,
823
) -> wasmtime::Result<Flag4>
824
where
825
<S as wasmtime::AsContext>::Data: Send,
826
{
827
let callee = unsafe {
828
wasmtime::component::TypedFunc::<
829
(Flag4,),
830
(Flag4,),
831
>::new_unchecked(self.roundtrip_flag4)
832
};
833
let (ret0,) = callee
834
.call_async(store.as_context_mut(), (arg0,))
835
.await?;
836
callee.post_return_async(store.as_context_mut()).await?;
837
Ok(ret0)
838
}
839
pub async fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(
840
&self,
841
mut store: S,
842
arg0: Flag8,
843
) -> wasmtime::Result<Flag8>
844
where
845
<S as wasmtime::AsContext>::Data: Send,
846
{
847
let callee = unsafe {
848
wasmtime::component::TypedFunc::<
849
(Flag8,),
850
(Flag8,),
851
>::new_unchecked(self.roundtrip_flag8)
852
};
853
let (ret0,) = callee
854
.call_async(store.as_context_mut(), (arg0,))
855
.await?;
856
callee.post_return_async(store.as_context_mut()).await?;
857
Ok(ret0)
858
}
859
pub async fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(
860
&self,
861
mut store: S,
862
arg0: Flag16,
863
) -> wasmtime::Result<Flag16>
864
where
865
<S as wasmtime::AsContext>::Data: Send,
866
{
867
let callee = unsafe {
868
wasmtime::component::TypedFunc::<
869
(Flag16,),
870
(Flag16,),
871
>::new_unchecked(self.roundtrip_flag16)
872
};
873
let (ret0,) = callee
874
.call_async(store.as_context_mut(), (arg0,))
875
.await?;
876
callee.post_return_async(store.as_context_mut()).await?;
877
Ok(ret0)
878
}
879
pub async fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(
880
&self,
881
mut store: S,
882
arg0: Flag32,
883
) -> wasmtime::Result<Flag32>
884
where
885
<S as wasmtime::AsContext>::Data: Send,
886
{
887
let callee = unsafe {
888
wasmtime::component::TypedFunc::<
889
(Flag32,),
890
(Flag32,),
891
>::new_unchecked(self.roundtrip_flag32)
892
};
893
let (ret0,) = callee
894
.call_async(store.as_context_mut(), (arg0,))
895
.await?;
896
callee.post_return_async(store.as_context_mut()).await?;
897
Ok(ret0)
898
}
899
pub async fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(
900
&self,
901
mut store: S,
902
arg0: Flag64,
903
) -> wasmtime::Result<Flag64>
904
where
905
<S as wasmtime::AsContext>::Data: Send,
906
{
907
let callee = unsafe {
908
wasmtime::component::TypedFunc::<
909
(Flag64,),
910
(Flag64,),
911
>::new_unchecked(self.roundtrip_flag64)
912
};
913
let (ret0,) = callee
914
.call_async(store.as_context_mut(), (arg0,))
915
.await?;
916
callee.post_return_async(store.as_context_mut()).await?;
917
Ok(ret0)
918
}
919
}
920
}
921
}
922
}
923
}
924
925