Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/component-macro/tests/expanded/flags.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,
177
for<'a> D::Data<'a>: foo::foo::flegs::Host,
178
T: 'static,
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 {}
309
impl<_T: ?Sized> HostWithStore for _T
310
where
311
_T: wasmtime::component::HasData,
312
{}
313
pub trait Host {
314
fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1;
315
fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2;
316
fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4;
317
fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8;
318
fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16;
319
fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32;
320
fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64;
321
}
322
impl<_T: Host + ?Sized> Host for &mut _T {
323
fn roundtrip_flag1(&mut self, x: Flag1) -> Flag1 {
324
Host::roundtrip_flag1(*self, x)
325
}
326
fn roundtrip_flag2(&mut self, x: Flag2) -> Flag2 {
327
Host::roundtrip_flag2(*self, x)
328
}
329
fn roundtrip_flag4(&mut self, x: Flag4) -> Flag4 {
330
Host::roundtrip_flag4(*self, x)
331
}
332
fn roundtrip_flag8(&mut self, x: Flag8) -> Flag8 {
333
Host::roundtrip_flag8(*self, x)
334
}
335
fn roundtrip_flag16(&mut self, x: Flag16) -> Flag16 {
336
Host::roundtrip_flag16(*self, x)
337
}
338
fn roundtrip_flag32(&mut self, x: Flag32) -> Flag32 {
339
Host::roundtrip_flag32(*self, x)
340
}
341
fn roundtrip_flag64(&mut self, x: Flag64) -> Flag64 {
342
Host::roundtrip_flag64(*self, x)
343
}
344
}
345
pub fn add_to_linker<T, D>(
346
linker: &mut wasmtime::component::Linker<T>,
347
host_getter: fn(&mut T) -> D::Data<'_>,
348
) -> wasmtime::Result<()>
349
where
350
D: HostWithStore,
351
for<'a> D::Data<'a>: Host,
352
T: 'static,
353
{
354
let mut inst = linker.instance("foo:foo/flegs")?;
355
inst.func_wrap(
356
"roundtrip-flag1",
357
move |
358
mut caller: wasmtime::StoreContextMut<'_, T>,
359
(arg0,): (Flag1,)|
360
{
361
let host = &mut host_getter(caller.data_mut());
362
let r = Host::roundtrip_flag1(host, arg0);
363
Ok((r,))
364
},
365
)?;
366
inst.func_wrap(
367
"roundtrip-flag2",
368
move |
369
mut caller: wasmtime::StoreContextMut<'_, T>,
370
(arg0,): (Flag2,)|
371
{
372
let host = &mut host_getter(caller.data_mut());
373
let r = Host::roundtrip_flag2(host, arg0);
374
Ok((r,))
375
},
376
)?;
377
inst.func_wrap(
378
"roundtrip-flag4",
379
move |
380
mut caller: wasmtime::StoreContextMut<'_, T>,
381
(arg0,): (Flag4,)|
382
{
383
let host = &mut host_getter(caller.data_mut());
384
let r = Host::roundtrip_flag4(host, arg0);
385
Ok((r,))
386
},
387
)?;
388
inst.func_wrap(
389
"roundtrip-flag8",
390
move |
391
mut caller: wasmtime::StoreContextMut<'_, T>,
392
(arg0,): (Flag8,)|
393
{
394
let host = &mut host_getter(caller.data_mut());
395
let r = Host::roundtrip_flag8(host, arg0);
396
Ok((r,))
397
},
398
)?;
399
inst.func_wrap(
400
"roundtrip-flag16",
401
move |
402
mut caller: wasmtime::StoreContextMut<'_, T>,
403
(arg0,): (Flag16,)|
404
{
405
let host = &mut host_getter(caller.data_mut());
406
let r = Host::roundtrip_flag16(host, arg0);
407
Ok((r,))
408
},
409
)?;
410
inst.func_wrap(
411
"roundtrip-flag32",
412
move |
413
mut caller: wasmtime::StoreContextMut<'_, T>,
414
(arg0,): (Flag32,)|
415
{
416
let host = &mut host_getter(caller.data_mut());
417
let r = Host::roundtrip_flag32(host, arg0);
418
Ok((r,))
419
},
420
)?;
421
inst.func_wrap(
422
"roundtrip-flag64",
423
move |
424
mut caller: wasmtime::StoreContextMut<'_, T>,
425
(arg0,): (Flag64,)|
426
{
427
let host = &mut host_getter(caller.data_mut());
428
let r = Host::roundtrip_flag64(host, arg0);
429
Ok((r,))
430
},
431
)?;
432
Ok(())
433
}
434
}
435
}
436
}
437
pub mod exports {
438
pub mod foo {
439
pub mod foo {
440
#[allow(clippy::all)]
441
pub mod flegs {
442
#[allow(unused_imports)]
443
use wasmtime::component::__internal::{anyhow, Box};
444
wasmtime::component::flags!(
445
Flag1 { #[component(name = "b0")] const B0; }
446
);
447
const _: () = {
448
assert!(
449
1 == < Flag1 as wasmtime::component::ComponentType >::SIZE32
450
);
451
assert!(
452
1 == < Flag1 as wasmtime::component::ComponentType >::ALIGN32
453
);
454
};
455
wasmtime::component::flags!(
456
Flag2 { #[component(name = "b0")] const B0; #[component(name = "b1")]
457
const B1; }
458
);
459
const _: () = {
460
assert!(
461
1 == < Flag2 as wasmtime::component::ComponentType >::SIZE32
462
);
463
assert!(
464
1 == < Flag2 as wasmtime::component::ComponentType >::ALIGN32
465
);
466
};
467
wasmtime::component::flags!(
468
Flag4 { #[component(name = "b0")] const B0; #[component(name = "b1")]
469
const B1; #[component(name = "b2")] const B2; #[component(name =
470
"b3")] const B3; }
471
);
472
const _: () = {
473
assert!(
474
1 == < Flag4 as wasmtime::component::ComponentType >::SIZE32
475
);
476
assert!(
477
1 == < Flag4 as wasmtime::component::ComponentType >::ALIGN32
478
);
479
};
480
wasmtime::component::flags!(
481
Flag8 { #[component(name = "b0")] const B0; #[component(name = "b1")]
482
const B1; #[component(name = "b2")] const B2; #[component(name =
483
"b3")] const B3; #[component(name = "b4")] const B4; #[component(name
484
= "b5")] const B5; #[component(name = "b6")] const B6;
485
#[component(name = "b7")] const B7; }
486
);
487
const _: () = {
488
assert!(
489
1 == < Flag8 as wasmtime::component::ComponentType >::SIZE32
490
);
491
assert!(
492
1 == < Flag8 as wasmtime::component::ComponentType >::ALIGN32
493
);
494
};
495
wasmtime::component::flags!(
496
Flag16 { #[component(name = "b0")] const B0; #[component(name =
497
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
498
= "b3")] const B3; #[component(name = "b4")] const B4;
499
#[component(name = "b5")] const B5; #[component(name = "b6")] const
500
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
501
const B8; #[component(name = "b9")] const B9; #[component(name =
502
"b10")] const B10; #[component(name = "b11")] const B11;
503
#[component(name = "b12")] const B12; #[component(name = "b13")]
504
const B13; #[component(name = "b14")] const B14; #[component(name =
505
"b15")] const B15; }
506
);
507
const _: () = {
508
assert!(
509
2 == < Flag16 as wasmtime::component::ComponentType >::SIZE32
510
);
511
assert!(
512
2 == < Flag16 as wasmtime::component::ComponentType >::ALIGN32
513
);
514
};
515
wasmtime::component::flags!(
516
Flag32 { #[component(name = "b0")] const B0; #[component(name =
517
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
518
= "b3")] const B3; #[component(name = "b4")] const B4;
519
#[component(name = "b5")] const B5; #[component(name = "b6")] const
520
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
521
const B8; #[component(name = "b9")] const B9; #[component(name =
522
"b10")] const B10; #[component(name = "b11")] const B11;
523
#[component(name = "b12")] const B12; #[component(name = "b13")]
524
const B13; #[component(name = "b14")] const B14; #[component(name =
525
"b15")] const B15; #[component(name = "b16")] const B16;
526
#[component(name = "b17")] const B17; #[component(name = "b18")]
527
const B18; #[component(name = "b19")] const B19; #[component(name =
528
"b20")] const B20; #[component(name = "b21")] const B21;
529
#[component(name = "b22")] const B22; #[component(name = "b23")]
530
const B23; #[component(name = "b24")] const B24; #[component(name =
531
"b25")] const B25; #[component(name = "b26")] const B26;
532
#[component(name = "b27")] const B27; #[component(name = "b28")]
533
const B28; #[component(name = "b29")] const B29; #[component(name =
534
"b30")] const B30; #[component(name = "b31")] const B31; }
535
);
536
const _: () = {
537
assert!(
538
4 == < Flag32 as wasmtime::component::ComponentType >::SIZE32
539
);
540
assert!(
541
4 == < Flag32 as wasmtime::component::ComponentType >::ALIGN32
542
);
543
};
544
wasmtime::component::flags!(
545
Flag64 { #[component(name = "b0")] const B0; #[component(name =
546
"b1")] const B1; #[component(name = "b2")] const B2; #[component(name
547
= "b3")] const B3; #[component(name = "b4")] const B4;
548
#[component(name = "b5")] const B5; #[component(name = "b6")] const
549
B6; #[component(name = "b7")] const B7; #[component(name = "b8")]
550
const B8; #[component(name = "b9")] const B9; #[component(name =
551
"b10")] const B10; #[component(name = "b11")] const B11;
552
#[component(name = "b12")] const B12; #[component(name = "b13")]
553
const B13; #[component(name = "b14")] const B14; #[component(name =
554
"b15")] const B15; #[component(name = "b16")] const B16;
555
#[component(name = "b17")] const B17; #[component(name = "b18")]
556
const B18; #[component(name = "b19")] const B19; #[component(name =
557
"b20")] const B20; #[component(name = "b21")] const B21;
558
#[component(name = "b22")] const B22; #[component(name = "b23")]
559
const B23; #[component(name = "b24")] const B24; #[component(name =
560
"b25")] const B25; #[component(name = "b26")] const B26;
561
#[component(name = "b27")] const B27; #[component(name = "b28")]
562
const B28; #[component(name = "b29")] const B29; #[component(name =
563
"b30")] const B30; #[component(name = "b31")] const B31;
564
#[component(name = "b32")] const B32; #[component(name = "b33")]
565
const B33; #[component(name = "b34")] const B34; #[component(name =
566
"b35")] const B35; #[component(name = "b36")] const B36;
567
#[component(name = "b37")] const B37; #[component(name = "b38")]
568
const B38; #[component(name = "b39")] const B39; #[component(name =
569
"b40")] const B40; #[component(name = "b41")] const B41;
570
#[component(name = "b42")] const B42; #[component(name = "b43")]
571
const B43; #[component(name = "b44")] const B44; #[component(name =
572
"b45")] const B45; #[component(name = "b46")] const B46;
573
#[component(name = "b47")] const B47; #[component(name = "b48")]
574
const B48; #[component(name = "b49")] const B49; #[component(name =
575
"b50")] const B50; #[component(name = "b51")] const B51;
576
#[component(name = "b52")] const B52; #[component(name = "b53")]
577
const B53; #[component(name = "b54")] const B54; #[component(name =
578
"b55")] const B55; #[component(name = "b56")] const B56;
579
#[component(name = "b57")] const B57; #[component(name = "b58")]
580
const B58; #[component(name = "b59")] const B59; #[component(name =
581
"b60")] const B60; #[component(name = "b61")] const B61;
582
#[component(name = "b62")] const B62; #[component(name = "b63")]
583
const B63; }
584
);
585
const _: () = {
586
assert!(
587
8 == < Flag64 as wasmtime::component::ComponentType >::SIZE32
588
);
589
assert!(
590
4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32
591
);
592
};
593
pub struct Guest {
594
roundtrip_flag1: wasmtime::component::Func,
595
roundtrip_flag2: wasmtime::component::Func,
596
roundtrip_flag4: wasmtime::component::Func,
597
roundtrip_flag8: wasmtime::component::Func,
598
roundtrip_flag16: wasmtime::component::Func,
599
roundtrip_flag32: wasmtime::component::Func,
600
roundtrip_flag64: wasmtime::component::Func,
601
}
602
#[derive(Clone)]
603
pub struct GuestIndices {
604
roundtrip_flag1: wasmtime::component::ComponentExportIndex,
605
roundtrip_flag2: wasmtime::component::ComponentExportIndex,
606
roundtrip_flag4: wasmtime::component::ComponentExportIndex,
607
roundtrip_flag8: wasmtime::component::ComponentExportIndex,
608
roundtrip_flag16: wasmtime::component::ComponentExportIndex,
609
roundtrip_flag32: wasmtime::component::ComponentExportIndex,
610
roundtrip_flag64: wasmtime::component::ComponentExportIndex,
611
}
612
impl GuestIndices {
613
/// Constructor for [`GuestIndices`] which takes a
614
/// [`Component`](wasmtime::component::Component) as input and can be executed
615
/// before instantiation.
616
///
617
/// This constructor can be used to front-load string lookups to find exports
618
/// within a component.
619
pub fn new<_T>(
620
_instance_pre: &wasmtime::component::InstancePre<_T>,
621
) -> wasmtime::Result<GuestIndices> {
622
let instance = _instance_pre
623
.component()
624
.get_export_index(None, "foo:foo/flegs")
625
.ok_or_else(|| {
626
anyhow::anyhow!(
627
"no exported instance named `foo:foo/flegs`"
628
)
629
})?;
630
let mut lookup = move |name| {
631
_instance_pre
632
.component()
633
.get_export_index(Some(&instance), name)
634
.ok_or_else(|| {
635
anyhow::anyhow!(
636
"instance export `foo:foo/flegs` does \
637
not have export `{name}`"
638
)
639
})
640
};
641
let _ = &mut lookup;
642
let roundtrip_flag1 = lookup("roundtrip-flag1")?;
643
let roundtrip_flag2 = lookup("roundtrip-flag2")?;
644
let roundtrip_flag4 = lookup("roundtrip-flag4")?;
645
let roundtrip_flag8 = lookup("roundtrip-flag8")?;
646
let roundtrip_flag16 = lookup("roundtrip-flag16")?;
647
let roundtrip_flag32 = lookup("roundtrip-flag32")?;
648
let roundtrip_flag64 = lookup("roundtrip-flag64")?;
649
Ok(GuestIndices {
650
roundtrip_flag1,
651
roundtrip_flag2,
652
roundtrip_flag4,
653
roundtrip_flag8,
654
roundtrip_flag16,
655
roundtrip_flag32,
656
roundtrip_flag64,
657
})
658
}
659
pub fn load(
660
&self,
661
mut store: impl wasmtime::AsContextMut,
662
instance: &wasmtime::component::Instance,
663
) -> wasmtime::Result<Guest> {
664
let _instance = instance;
665
let _instance_pre = _instance.instance_pre(&store);
666
let _instance_type = _instance_pre.instance_type();
667
let mut store = store.as_context_mut();
668
let _ = &mut store;
669
let roundtrip_flag1 = *_instance
670
.get_typed_func::<
671
(Flag1,),
672
(Flag1,),
673
>(&mut store, &self.roundtrip_flag1)?
674
.func();
675
let roundtrip_flag2 = *_instance
676
.get_typed_func::<
677
(Flag2,),
678
(Flag2,),
679
>(&mut store, &self.roundtrip_flag2)?
680
.func();
681
let roundtrip_flag4 = *_instance
682
.get_typed_func::<
683
(Flag4,),
684
(Flag4,),
685
>(&mut store, &self.roundtrip_flag4)?
686
.func();
687
let roundtrip_flag8 = *_instance
688
.get_typed_func::<
689
(Flag8,),
690
(Flag8,),
691
>(&mut store, &self.roundtrip_flag8)?
692
.func();
693
let roundtrip_flag16 = *_instance
694
.get_typed_func::<
695
(Flag16,),
696
(Flag16,),
697
>(&mut store, &self.roundtrip_flag16)?
698
.func();
699
let roundtrip_flag32 = *_instance
700
.get_typed_func::<
701
(Flag32,),
702
(Flag32,),
703
>(&mut store, &self.roundtrip_flag32)?
704
.func();
705
let roundtrip_flag64 = *_instance
706
.get_typed_func::<
707
(Flag64,),
708
(Flag64,),
709
>(&mut store, &self.roundtrip_flag64)?
710
.func();
711
Ok(Guest {
712
roundtrip_flag1,
713
roundtrip_flag2,
714
roundtrip_flag4,
715
roundtrip_flag8,
716
roundtrip_flag16,
717
roundtrip_flag32,
718
roundtrip_flag64,
719
})
720
}
721
}
722
impl Guest {
723
pub fn call_roundtrip_flag1<S: wasmtime::AsContextMut>(
724
&self,
725
mut store: S,
726
arg0: Flag1,
727
) -> wasmtime::Result<Flag1> {
728
let callee = unsafe {
729
wasmtime::component::TypedFunc::<
730
(Flag1,),
731
(Flag1,),
732
>::new_unchecked(self.roundtrip_flag1)
733
};
734
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
735
callee.post_return(store.as_context_mut())?;
736
Ok(ret0)
737
}
738
pub fn call_roundtrip_flag2<S: wasmtime::AsContextMut>(
739
&self,
740
mut store: S,
741
arg0: Flag2,
742
) -> wasmtime::Result<Flag2> {
743
let callee = unsafe {
744
wasmtime::component::TypedFunc::<
745
(Flag2,),
746
(Flag2,),
747
>::new_unchecked(self.roundtrip_flag2)
748
};
749
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
750
callee.post_return(store.as_context_mut())?;
751
Ok(ret0)
752
}
753
pub fn call_roundtrip_flag4<S: wasmtime::AsContextMut>(
754
&self,
755
mut store: S,
756
arg0: Flag4,
757
) -> wasmtime::Result<Flag4> {
758
let callee = unsafe {
759
wasmtime::component::TypedFunc::<
760
(Flag4,),
761
(Flag4,),
762
>::new_unchecked(self.roundtrip_flag4)
763
};
764
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
765
callee.post_return(store.as_context_mut())?;
766
Ok(ret0)
767
}
768
pub fn call_roundtrip_flag8<S: wasmtime::AsContextMut>(
769
&self,
770
mut store: S,
771
arg0: Flag8,
772
) -> wasmtime::Result<Flag8> {
773
let callee = unsafe {
774
wasmtime::component::TypedFunc::<
775
(Flag8,),
776
(Flag8,),
777
>::new_unchecked(self.roundtrip_flag8)
778
};
779
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
780
callee.post_return(store.as_context_mut())?;
781
Ok(ret0)
782
}
783
pub fn call_roundtrip_flag16<S: wasmtime::AsContextMut>(
784
&self,
785
mut store: S,
786
arg0: Flag16,
787
) -> wasmtime::Result<Flag16> {
788
let callee = unsafe {
789
wasmtime::component::TypedFunc::<
790
(Flag16,),
791
(Flag16,),
792
>::new_unchecked(self.roundtrip_flag16)
793
};
794
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
795
callee.post_return(store.as_context_mut())?;
796
Ok(ret0)
797
}
798
pub fn call_roundtrip_flag32<S: wasmtime::AsContextMut>(
799
&self,
800
mut store: S,
801
arg0: Flag32,
802
) -> wasmtime::Result<Flag32> {
803
let callee = unsafe {
804
wasmtime::component::TypedFunc::<
805
(Flag32,),
806
(Flag32,),
807
>::new_unchecked(self.roundtrip_flag32)
808
};
809
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
810
callee.post_return(store.as_context_mut())?;
811
Ok(ret0)
812
}
813
pub fn call_roundtrip_flag64<S: wasmtime::AsContextMut>(
814
&self,
815
mut store: S,
816
arg0: Flag64,
817
) -> wasmtime::Result<Flag64> {
818
let callee = unsafe {
819
wasmtime::component::TypedFunc::<
820
(Flag64,),
821
(Flag64,),
822
>::new_unchecked(self.roundtrip_flag64)
823
};
824
let (ret0,) = callee.call(store.as_context_mut(), (arg0,))?;
825
callee.post_return(store.as_context_mut())?;
826
Ok(ret0)
827
}
828
}
829
}
830
}
831
}
832
}
833
834