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