Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/component-macro/tests/expanded/conventions_async.rs
1692 views
1
/// Auto-generated bindings for a pre-instantiated version of a
2
/// component which implements the world `the-world`.
3
///
4
/// This structure is created through [`TheWorldPre::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 [`TheWorld`] as well.
9
pub struct TheWorldPre<T: 'static> {
10
instance_pre: wasmtime::component::InstancePre<T>,
11
indices: TheWorldIndices,
12
}
13
impl<T: 'static> Clone for TheWorldPre<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> TheWorldPre<_T> {
22
/// Creates a new copy of `TheWorldPre` 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 = TheWorldIndices::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 [`TheWorld`] 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<TheWorld> {
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> TheWorldPre<_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<TheWorld> {
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-world`.
68
///
69
/// This is an implementation detail of [`TheWorldPre`] and can
70
/// be constructed if needed as well.
71
///
72
/// For more information see [`TheWorld`] as well.
73
#[derive(Clone)]
74
pub struct TheWorldIndices {
75
interface0: exports::foo::foo::conventions::GuestIndices,
76
}
77
/// Auto-generated bindings for an instance a component which
78
/// implements the world `the-world`.
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
/// [`TheWorld::instantiate`] which only needs a
85
/// [`Store`], [`Component`], and [`Linker`].
86
///
87
/// * Alternatively you can create a [`TheWorldPre`] 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 [`TheWorldPre::instantiate`] to
91
/// create a [`TheWorld`].
92
///
93
/// * If you've instantiated the instance yourself already
94
/// then you can use [`TheWorld::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 TheWorld {
103
interface0: exports::foo::foo::conventions::Guest,
104
}
105
const _: () = {
106
#[allow(unused_imports)]
107
use wasmtime::component::__internal::anyhow;
108
impl TheWorldIndices {
109
/// Creates a new copy of `TheWorldIndices` 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::conventions::GuestIndices::new(
120
_instance_pre,
121
)?;
122
Ok(TheWorldIndices { interface0 })
123
}
124
/// Uses the indices stored in `self` to load an instance
125
/// of [`TheWorld`] from the instance provided.
126
///
127
/// Note that at this time this method will additionally
128
/// perform type-checks of all exports.
129
pub fn load(
130
&self,
131
mut store: impl wasmtime::AsContextMut,
132
instance: &wasmtime::component::Instance,
133
) -> wasmtime::Result<TheWorld> {
134
let _ = &mut store;
135
let _instance = instance;
136
let interface0 = self.interface0.load(&mut store, &_instance)?;
137
Ok(TheWorld { interface0 })
138
}
139
}
140
impl TheWorld {
141
/// Convenience wrapper around [`TheWorldPre::new`] and
142
/// [`TheWorldPre::instantiate`].
143
pub fn instantiate<_T>(
144
store: impl wasmtime::AsContextMut<Data = _T>,
145
component: &wasmtime::component::Component,
146
linker: &wasmtime::component::Linker<_T>,
147
) -> wasmtime::Result<TheWorld> {
148
let pre = linker.instantiate_pre(component)?;
149
TheWorldPre::new(pre)?.instantiate(store)
150
}
151
/// Convenience wrapper around [`TheWorldIndices::new`] and
152
/// [`TheWorldIndices::load`].
153
pub fn new(
154
mut store: impl wasmtime::AsContextMut,
155
instance: &wasmtime::component::Instance,
156
) -> wasmtime::Result<TheWorld> {
157
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
158
indices.load(&mut store, instance)
159
}
160
/// Convenience wrapper around [`TheWorldPre::new`] and
161
/// [`TheWorldPre::instantiate_async`].
162
pub async fn instantiate_async<_T>(
163
store: impl wasmtime::AsContextMut<Data = _T>,
164
component: &wasmtime::component::Component,
165
linker: &wasmtime::component::Linker<_T>,
166
) -> wasmtime::Result<TheWorld>
167
where
168
_T: Send,
169
{
170
let pre = linker.instantiate_pre(component)?;
171
TheWorldPre::new(pre)?.instantiate_async(store).await
172
}
173
pub fn add_to_linker<T, D>(
174
linker: &mut wasmtime::component::Linker<T>,
175
host_getter: fn(&mut T) -> D::Data<'_>,
176
) -> wasmtime::Result<()>
177
where
178
D: foo::foo::conventions::HostWithStore + Send,
179
for<'a> D::Data<'a>: foo::foo::conventions::Host + Send,
180
T: 'static + Send,
181
{
182
foo::foo::conventions::add_to_linker::<T, D>(linker, host_getter)?;
183
Ok(())
184
}
185
pub fn foo_foo_conventions(&self) -> &exports::foo::foo::conventions::Guest {
186
&self.interface0
187
}
188
}
189
};
190
pub mod foo {
191
pub mod foo {
192
#[allow(clippy::all)]
193
pub mod conventions {
194
#[allow(unused_imports)]
195
use wasmtime::component::__internal::{anyhow, Box};
196
#[derive(wasmtime::component::ComponentType)]
197
#[derive(wasmtime::component::Lift)]
198
#[derive(wasmtime::component::Lower)]
199
#[component(record)]
200
#[derive(Clone, Copy)]
201
pub struct LudicrousSpeed {
202
#[component(name = "how-fast-are-you-going")]
203
pub how_fast_are_you_going: u32,
204
#[component(name = "i-am-going-extremely-slow")]
205
pub i_am_going_extremely_slow: u64,
206
}
207
impl core::fmt::Debug for LudicrousSpeed {
208
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
209
f.debug_struct("LudicrousSpeed")
210
.field("how-fast-are-you-going", &self.how_fast_are_you_going)
211
.field(
212
"i-am-going-extremely-slow",
213
&self.i_am_going_extremely_slow,
214
)
215
.finish()
216
}
217
}
218
const _: () = {
219
assert!(
220
16 == < LudicrousSpeed as wasmtime::component::ComponentType
221
>::SIZE32
222
);
223
assert!(
224
8 == < LudicrousSpeed as wasmtime::component::ComponentType
225
>::ALIGN32
226
);
227
};
228
pub trait HostWithStore: wasmtime::component::HasData + Send {}
229
impl<_T: ?Sized> HostWithStore for _T
230
where
231
_T: wasmtime::component::HasData + Send,
232
{}
233
pub trait Host: Send {
234
fn kebab_case(
235
&mut self,
236
) -> impl ::core::future::Future<Output = ()> + Send;
237
fn foo(
238
&mut self,
239
x: LudicrousSpeed,
240
) -> impl ::core::future::Future<Output = ()> + Send;
241
fn function_with_dashes(
242
&mut self,
243
) -> impl ::core::future::Future<Output = ()> + Send;
244
fn function_with_no_weird_characters(
245
&mut self,
246
) -> impl ::core::future::Future<Output = ()> + Send;
247
fn apple(&mut self) -> impl ::core::future::Future<Output = ()> + Send;
248
fn apple_pear(
249
&mut self,
250
) -> impl ::core::future::Future<Output = ()> + Send;
251
fn apple_pear_grape(
252
&mut self,
253
) -> impl ::core::future::Future<Output = ()> + Send;
254
fn a0(&mut self) -> impl ::core::future::Future<Output = ()> + Send;
255
/// Comment out identifiers that collide when mapped to snake_case, for now; see
256
/// https://github.com/WebAssembly/component-model/issues/118
257
/// APPLE: func()
258
/// APPLE-pear-GRAPE: func()
259
/// apple-PEAR-grape: func()
260
fn is_xml(&mut self) -> impl ::core::future::Future<Output = ()> + Send;
261
fn explicit(
262
&mut self,
263
) -> impl ::core::future::Future<Output = ()> + Send;
264
fn explicit_kebab(
265
&mut self,
266
) -> impl ::core::future::Future<Output = ()> + Send;
267
/// Identifiers with the same name as keywords are quoted.
268
fn bool(&mut self) -> impl ::core::future::Future<Output = ()> + Send;
269
}
270
impl<_T: Host + ?Sized + Send> Host for &mut _T {
271
fn kebab_case(
272
&mut self,
273
) -> impl ::core::future::Future<Output = ()> + Send {
274
async move { Host::kebab_case(*self).await }
275
}
276
fn foo(
277
&mut self,
278
x: LudicrousSpeed,
279
) -> impl ::core::future::Future<Output = ()> + Send {
280
async move { Host::foo(*self, x).await }
281
}
282
fn function_with_dashes(
283
&mut self,
284
) -> impl ::core::future::Future<Output = ()> + Send {
285
async move { Host::function_with_dashes(*self).await }
286
}
287
fn function_with_no_weird_characters(
288
&mut self,
289
) -> impl ::core::future::Future<Output = ()> + Send {
290
async move { Host::function_with_no_weird_characters(*self).await }
291
}
292
fn apple(&mut self) -> impl ::core::future::Future<Output = ()> + Send {
293
async move { Host::apple(*self).await }
294
}
295
fn apple_pear(
296
&mut self,
297
) -> impl ::core::future::Future<Output = ()> + Send {
298
async move { Host::apple_pear(*self).await }
299
}
300
fn apple_pear_grape(
301
&mut self,
302
) -> impl ::core::future::Future<Output = ()> + Send {
303
async move { Host::apple_pear_grape(*self).await }
304
}
305
fn a0(&mut self) -> impl ::core::future::Future<Output = ()> + Send {
306
async move { Host::a0(*self).await }
307
}
308
/// Comment out identifiers that collide when mapped to snake_case, for now; see
309
/// https://github.com/WebAssembly/component-model/issues/118
310
/// APPLE: func()
311
/// APPLE-pear-GRAPE: func()
312
/// apple-PEAR-grape: func()
313
fn is_xml(&mut self) -> impl ::core::future::Future<Output = ()> + Send {
314
async move { Host::is_xml(*self).await }
315
}
316
fn explicit(
317
&mut self,
318
) -> impl ::core::future::Future<Output = ()> + Send {
319
async move { Host::explicit(*self).await }
320
}
321
fn explicit_kebab(
322
&mut self,
323
) -> impl ::core::future::Future<Output = ()> + Send {
324
async move { Host::explicit_kebab(*self).await }
325
}
326
/// Identifiers with the same name as keywords are quoted.
327
fn bool(&mut self) -> impl ::core::future::Future<Output = ()> + Send {
328
async move { Host::bool(*self).await }
329
}
330
}
331
pub fn add_to_linker<T, D>(
332
linker: &mut wasmtime::component::Linker<T>,
333
host_getter: fn(&mut T) -> D::Data<'_>,
334
) -> wasmtime::Result<()>
335
where
336
D: HostWithStore,
337
for<'a> D::Data<'a>: Host,
338
T: 'static + Send,
339
{
340
let mut inst = linker.instance("foo:foo/conventions")?;
341
inst.func_wrap_async(
342
"kebab-case",
343
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
344
wasmtime::component::__internal::Box::new(async move {
345
let host = &mut host_getter(caller.data_mut());
346
let r = Host::kebab_case(host).await;
347
Ok(r)
348
})
349
},
350
)?;
351
inst.func_wrap_async(
352
"foo",
353
move |
354
mut caller: wasmtime::StoreContextMut<'_, T>,
355
(arg0,): (LudicrousSpeed,)|
356
{
357
wasmtime::component::__internal::Box::new(async move {
358
let host = &mut host_getter(caller.data_mut());
359
let r = Host::foo(host, arg0).await;
360
Ok(r)
361
})
362
},
363
)?;
364
inst.func_wrap_async(
365
"function-with-dashes",
366
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
367
wasmtime::component::__internal::Box::new(async move {
368
let host = &mut host_getter(caller.data_mut());
369
let r = Host::function_with_dashes(host).await;
370
Ok(r)
371
})
372
},
373
)?;
374
inst.func_wrap_async(
375
"function-with-no-weird-characters",
376
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
377
wasmtime::component::__internal::Box::new(async move {
378
let host = &mut host_getter(caller.data_mut());
379
let r = Host::function_with_no_weird_characters(host).await;
380
Ok(r)
381
})
382
},
383
)?;
384
inst.func_wrap_async(
385
"apple",
386
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
387
wasmtime::component::__internal::Box::new(async move {
388
let host = &mut host_getter(caller.data_mut());
389
let r = Host::apple(host).await;
390
Ok(r)
391
})
392
},
393
)?;
394
inst.func_wrap_async(
395
"apple-pear",
396
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
397
wasmtime::component::__internal::Box::new(async move {
398
let host = &mut host_getter(caller.data_mut());
399
let r = Host::apple_pear(host).await;
400
Ok(r)
401
})
402
},
403
)?;
404
inst.func_wrap_async(
405
"apple-pear-grape",
406
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
407
wasmtime::component::__internal::Box::new(async move {
408
let host = &mut host_getter(caller.data_mut());
409
let r = Host::apple_pear_grape(host).await;
410
Ok(r)
411
})
412
},
413
)?;
414
inst.func_wrap_async(
415
"a0",
416
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
417
wasmtime::component::__internal::Box::new(async move {
418
let host = &mut host_getter(caller.data_mut());
419
let r = Host::a0(host).await;
420
Ok(r)
421
})
422
},
423
)?;
424
inst.func_wrap_async(
425
"is-XML",
426
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
427
wasmtime::component::__internal::Box::new(async move {
428
let host = &mut host_getter(caller.data_mut());
429
let r = Host::is_xml(host).await;
430
Ok(r)
431
})
432
},
433
)?;
434
inst.func_wrap_async(
435
"explicit",
436
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
437
wasmtime::component::__internal::Box::new(async move {
438
let host = &mut host_getter(caller.data_mut());
439
let r = Host::explicit(host).await;
440
Ok(r)
441
})
442
},
443
)?;
444
inst.func_wrap_async(
445
"explicit-kebab",
446
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
447
wasmtime::component::__internal::Box::new(async move {
448
let host = &mut host_getter(caller.data_mut());
449
let r = Host::explicit_kebab(host).await;
450
Ok(r)
451
})
452
},
453
)?;
454
inst.func_wrap_async(
455
"bool",
456
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
457
wasmtime::component::__internal::Box::new(async move {
458
let host = &mut host_getter(caller.data_mut());
459
let r = Host::bool(host).await;
460
Ok(r)
461
})
462
},
463
)?;
464
Ok(())
465
}
466
}
467
}
468
}
469
pub mod exports {
470
pub mod foo {
471
pub mod foo {
472
#[allow(clippy::all)]
473
pub mod conventions {
474
#[allow(unused_imports)]
475
use wasmtime::component::__internal::{anyhow, Box};
476
#[derive(wasmtime::component::ComponentType)]
477
#[derive(wasmtime::component::Lift)]
478
#[derive(wasmtime::component::Lower)]
479
#[component(record)]
480
#[derive(Clone, Copy)]
481
pub struct LudicrousSpeed {
482
#[component(name = "how-fast-are-you-going")]
483
pub how_fast_are_you_going: u32,
484
#[component(name = "i-am-going-extremely-slow")]
485
pub i_am_going_extremely_slow: u64,
486
}
487
impl core::fmt::Debug for LudicrousSpeed {
488
fn fmt(
489
&self,
490
f: &mut core::fmt::Formatter<'_>,
491
) -> core::fmt::Result {
492
f.debug_struct("LudicrousSpeed")
493
.field(
494
"how-fast-are-you-going",
495
&self.how_fast_are_you_going,
496
)
497
.field(
498
"i-am-going-extremely-slow",
499
&self.i_am_going_extremely_slow,
500
)
501
.finish()
502
}
503
}
504
const _: () = {
505
assert!(
506
16 == < LudicrousSpeed as wasmtime::component::ComponentType
507
>::SIZE32
508
);
509
assert!(
510
8 == < LudicrousSpeed as wasmtime::component::ComponentType
511
>::ALIGN32
512
);
513
};
514
pub struct Guest {
515
kebab_case: wasmtime::component::Func,
516
foo: wasmtime::component::Func,
517
function_with_dashes: wasmtime::component::Func,
518
function_with_no_weird_characters: wasmtime::component::Func,
519
apple: wasmtime::component::Func,
520
apple_pear: wasmtime::component::Func,
521
apple_pear_grape: wasmtime::component::Func,
522
a0: wasmtime::component::Func,
523
is_xml: wasmtime::component::Func,
524
explicit: wasmtime::component::Func,
525
explicit_kebab: wasmtime::component::Func,
526
bool: wasmtime::component::Func,
527
}
528
#[derive(Clone)]
529
pub struct GuestIndices {
530
kebab_case: wasmtime::component::ComponentExportIndex,
531
foo: wasmtime::component::ComponentExportIndex,
532
function_with_dashes: wasmtime::component::ComponentExportIndex,
533
function_with_no_weird_characters: wasmtime::component::ComponentExportIndex,
534
apple: wasmtime::component::ComponentExportIndex,
535
apple_pear: wasmtime::component::ComponentExportIndex,
536
apple_pear_grape: wasmtime::component::ComponentExportIndex,
537
a0: wasmtime::component::ComponentExportIndex,
538
is_xml: wasmtime::component::ComponentExportIndex,
539
explicit: wasmtime::component::ComponentExportIndex,
540
explicit_kebab: wasmtime::component::ComponentExportIndex,
541
bool: wasmtime::component::ComponentExportIndex,
542
}
543
impl GuestIndices {
544
/// Constructor for [`GuestIndices`] which takes a
545
/// [`Component`](wasmtime::component::Component) as input and can be executed
546
/// before instantiation.
547
///
548
/// This constructor can be used to front-load string lookups to find exports
549
/// within a component.
550
pub fn new<_T>(
551
_instance_pre: &wasmtime::component::InstancePre<_T>,
552
) -> wasmtime::Result<GuestIndices> {
553
let instance = _instance_pre
554
.component()
555
.get_export_index(None, "foo:foo/conventions")
556
.ok_or_else(|| {
557
anyhow::anyhow!(
558
"no exported instance named `foo:foo/conventions`"
559
)
560
})?;
561
let mut lookup = move |name| {
562
_instance_pre
563
.component()
564
.get_export_index(Some(&instance), name)
565
.ok_or_else(|| {
566
anyhow::anyhow!(
567
"instance export `foo:foo/conventions` does \
568
not have export `{name}`"
569
)
570
})
571
};
572
let _ = &mut lookup;
573
let kebab_case = lookup("kebab-case")?;
574
let foo = lookup("foo")?;
575
let function_with_dashes = lookup("function-with-dashes")?;
576
let function_with_no_weird_characters = lookup(
577
"function-with-no-weird-characters",
578
)?;
579
let apple = lookup("apple")?;
580
let apple_pear = lookup("apple-pear")?;
581
let apple_pear_grape = lookup("apple-pear-grape")?;
582
let a0 = lookup("a0")?;
583
let is_xml = lookup("is-XML")?;
584
let explicit = lookup("explicit")?;
585
let explicit_kebab = lookup("explicit-kebab")?;
586
let bool = lookup("bool")?;
587
Ok(GuestIndices {
588
kebab_case,
589
foo,
590
function_with_dashes,
591
function_with_no_weird_characters,
592
apple,
593
apple_pear,
594
apple_pear_grape,
595
a0,
596
is_xml,
597
explicit,
598
explicit_kebab,
599
bool,
600
})
601
}
602
pub fn load(
603
&self,
604
mut store: impl wasmtime::AsContextMut,
605
instance: &wasmtime::component::Instance,
606
) -> wasmtime::Result<Guest> {
607
let _instance = instance;
608
let _instance_pre = _instance.instance_pre(&store);
609
let _instance_type = _instance_pre.instance_type();
610
let mut store = store.as_context_mut();
611
let _ = &mut store;
612
let kebab_case = *_instance
613
.get_typed_func::<(), ()>(&mut store, &self.kebab_case)?
614
.func();
615
let foo = *_instance
616
.get_typed_func::<
617
(LudicrousSpeed,),
618
(),
619
>(&mut store, &self.foo)?
620
.func();
621
let function_with_dashes = *_instance
622
.get_typed_func::<
623
(),
624
(),
625
>(&mut store, &self.function_with_dashes)?
626
.func();
627
let function_with_no_weird_characters = *_instance
628
.get_typed_func::<
629
(),
630
(),
631
>(&mut store, &self.function_with_no_weird_characters)?
632
.func();
633
let apple = *_instance
634
.get_typed_func::<(), ()>(&mut store, &self.apple)?
635
.func();
636
let apple_pear = *_instance
637
.get_typed_func::<(), ()>(&mut store, &self.apple_pear)?
638
.func();
639
let apple_pear_grape = *_instance
640
.get_typed_func::<
641
(),
642
(),
643
>(&mut store, &self.apple_pear_grape)?
644
.func();
645
let a0 = *_instance
646
.get_typed_func::<(), ()>(&mut store, &self.a0)?
647
.func();
648
let is_xml = *_instance
649
.get_typed_func::<(), ()>(&mut store, &self.is_xml)?
650
.func();
651
let explicit = *_instance
652
.get_typed_func::<(), ()>(&mut store, &self.explicit)?
653
.func();
654
let explicit_kebab = *_instance
655
.get_typed_func::<(), ()>(&mut store, &self.explicit_kebab)?
656
.func();
657
let bool = *_instance
658
.get_typed_func::<(), ()>(&mut store, &self.bool)?
659
.func();
660
Ok(Guest {
661
kebab_case,
662
foo,
663
function_with_dashes,
664
function_with_no_weird_characters,
665
apple,
666
apple_pear,
667
apple_pear_grape,
668
a0,
669
is_xml,
670
explicit,
671
explicit_kebab,
672
bool,
673
})
674
}
675
}
676
impl Guest {
677
pub async fn call_kebab_case<S: wasmtime::AsContextMut>(
678
&self,
679
mut store: S,
680
) -> wasmtime::Result<()>
681
where
682
<S as wasmtime::AsContext>::Data: Send,
683
{
684
let callee = unsafe {
685
wasmtime::component::TypedFunc::<
686
(),
687
(),
688
>::new_unchecked(self.kebab_case)
689
};
690
let () = callee.call_async(store.as_context_mut(), ()).await?;
691
callee.post_return_async(store.as_context_mut()).await?;
692
Ok(())
693
}
694
pub async fn call_foo<S: wasmtime::AsContextMut>(
695
&self,
696
mut store: S,
697
arg0: LudicrousSpeed,
698
) -> wasmtime::Result<()>
699
where
700
<S as wasmtime::AsContext>::Data: Send,
701
{
702
let callee = unsafe {
703
wasmtime::component::TypedFunc::<
704
(LudicrousSpeed,),
705
(),
706
>::new_unchecked(self.foo)
707
};
708
let () = callee
709
.call_async(store.as_context_mut(), (arg0,))
710
.await?;
711
callee.post_return_async(store.as_context_mut()).await?;
712
Ok(())
713
}
714
pub async fn call_function_with_dashes<S: wasmtime::AsContextMut>(
715
&self,
716
mut store: S,
717
) -> wasmtime::Result<()>
718
where
719
<S as wasmtime::AsContext>::Data: Send,
720
{
721
let callee = unsafe {
722
wasmtime::component::TypedFunc::<
723
(),
724
(),
725
>::new_unchecked(self.function_with_dashes)
726
};
727
let () = callee.call_async(store.as_context_mut(), ()).await?;
728
callee.post_return_async(store.as_context_mut()).await?;
729
Ok(())
730
}
731
pub async fn call_function_with_no_weird_characters<
732
S: wasmtime::AsContextMut,
733
>(&self, mut store: S) -> wasmtime::Result<()>
734
where
735
<S as wasmtime::AsContext>::Data: Send,
736
{
737
let callee = unsafe {
738
wasmtime::component::TypedFunc::<
739
(),
740
(),
741
>::new_unchecked(self.function_with_no_weird_characters)
742
};
743
let () = callee.call_async(store.as_context_mut(), ()).await?;
744
callee.post_return_async(store.as_context_mut()).await?;
745
Ok(())
746
}
747
pub async fn call_apple<S: wasmtime::AsContextMut>(
748
&self,
749
mut store: S,
750
) -> wasmtime::Result<()>
751
where
752
<S as wasmtime::AsContext>::Data: Send,
753
{
754
let callee = unsafe {
755
wasmtime::component::TypedFunc::<
756
(),
757
(),
758
>::new_unchecked(self.apple)
759
};
760
let () = callee.call_async(store.as_context_mut(), ()).await?;
761
callee.post_return_async(store.as_context_mut()).await?;
762
Ok(())
763
}
764
pub async fn call_apple_pear<S: wasmtime::AsContextMut>(
765
&self,
766
mut store: S,
767
) -> wasmtime::Result<()>
768
where
769
<S as wasmtime::AsContext>::Data: Send,
770
{
771
let callee = unsafe {
772
wasmtime::component::TypedFunc::<
773
(),
774
(),
775
>::new_unchecked(self.apple_pear)
776
};
777
let () = callee.call_async(store.as_context_mut(), ()).await?;
778
callee.post_return_async(store.as_context_mut()).await?;
779
Ok(())
780
}
781
pub async fn call_apple_pear_grape<S: wasmtime::AsContextMut>(
782
&self,
783
mut store: S,
784
) -> wasmtime::Result<()>
785
where
786
<S as wasmtime::AsContext>::Data: Send,
787
{
788
let callee = unsafe {
789
wasmtime::component::TypedFunc::<
790
(),
791
(),
792
>::new_unchecked(self.apple_pear_grape)
793
};
794
let () = callee.call_async(store.as_context_mut(), ()).await?;
795
callee.post_return_async(store.as_context_mut()).await?;
796
Ok(())
797
}
798
pub async fn call_a0<S: wasmtime::AsContextMut>(
799
&self,
800
mut store: S,
801
) -> wasmtime::Result<()>
802
where
803
<S as wasmtime::AsContext>::Data: Send,
804
{
805
let callee = unsafe {
806
wasmtime::component::TypedFunc::<
807
(),
808
(),
809
>::new_unchecked(self.a0)
810
};
811
let () = callee.call_async(store.as_context_mut(), ()).await?;
812
callee.post_return_async(store.as_context_mut()).await?;
813
Ok(())
814
}
815
/// Comment out identifiers that collide when mapped to snake_case, for now; see
816
/// https://github.com/WebAssembly/component-model/issues/118
817
/// APPLE: func()
818
/// APPLE-pear-GRAPE: func()
819
/// apple-PEAR-grape: func()
820
pub async fn call_is_xml<S: wasmtime::AsContextMut>(
821
&self,
822
mut store: S,
823
) -> wasmtime::Result<()>
824
where
825
<S as wasmtime::AsContext>::Data: Send,
826
{
827
let callee = unsafe {
828
wasmtime::component::TypedFunc::<
829
(),
830
(),
831
>::new_unchecked(self.is_xml)
832
};
833
let () = callee.call_async(store.as_context_mut(), ()).await?;
834
callee.post_return_async(store.as_context_mut()).await?;
835
Ok(())
836
}
837
pub async fn call_explicit<S: wasmtime::AsContextMut>(
838
&self,
839
mut store: S,
840
) -> wasmtime::Result<()>
841
where
842
<S as wasmtime::AsContext>::Data: Send,
843
{
844
let callee = unsafe {
845
wasmtime::component::TypedFunc::<
846
(),
847
(),
848
>::new_unchecked(self.explicit)
849
};
850
let () = callee.call_async(store.as_context_mut(), ()).await?;
851
callee.post_return_async(store.as_context_mut()).await?;
852
Ok(())
853
}
854
pub async fn call_explicit_kebab<S: wasmtime::AsContextMut>(
855
&self,
856
mut store: S,
857
) -> wasmtime::Result<()>
858
where
859
<S as wasmtime::AsContext>::Data: Send,
860
{
861
let callee = unsafe {
862
wasmtime::component::TypedFunc::<
863
(),
864
(),
865
>::new_unchecked(self.explicit_kebab)
866
};
867
let () = callee.call_async(store.as_context_mut(), ()).await?;
868
callee.post_return_async(store.as_context_mut()).await?;
869
Ok(())
870
}
871
/// Identifiers with the same name as keywords are quoted.
872
pub async fn call_bool<S: wasmtime::AsContextMut>(
873
&self,
874
mut store: S,
875
) -> wasmtime::Result<()>
876
where
877
<S as wasmtime::AsContext>::Data: Send,
878
{
879
let callee = unsafe {
880
wasmtime::component::TypedFunc::<
881
(),
882
(),
883
>::new_unchecked(self.bool)
884
};
885
let () = callee.call_async(store.as_context_mut(), ()).await?;
886
callee.post_return_async(store.as_context_mut()).await?;
887
Ok(())
888
}
889
}
890
}
891
}
892
}
893
}
894
895