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