A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
/// Auto-generated bindings for a pre-instantiated version of a
/// component which implements the world `my-world`.
///
/// This structure is created through [`MyWorldPre::new`] which
/// takes a [`InstancePre`](wasmtime::component::InstancePre) that
/// has been created through a [`Linker`](wasmtime::component::Linker).
///
/// For more information see [`MyWorld`] as well.
pub struct MyWorldPre<T: 'static> {
instance_pre: wasmtime::component::InstancePre<T>,
indices: MyWorldIndices,
}
impl<T: 'static> Clone for MyWorldPre<T> {
fn clone(&self) -> Self {
Self {
instance_pre: self.instance_pre.clone(),
indices: self.indices.clone(),
}
}
}
impl<_T: 'static> MyWorldPre<_T> {
/// Creates a new copy of `MyWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
/// This method may fail if the component behind `instance_pre`
/// does not have the required exports.
pub fn new(
instance_pre: wasmtime::component::InstancePre<_T>,
) -> wasmtime::Result<Self> {
let indices = MyWorldIndices::new(&instance_pre)?;
Ok(Self { instance_pre, indices })
}
pub fn engine(&self) -> &wasmtime::Engine {
self.instance_pre.engine()
}
pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
&self.instance_pre
}
/// Instantiates a new instance of [`MyWorld`] within the
/// `store` provided.
///
/// This function will use `self` as the pre-instantiated
/// instance to perform instantiation. Afterwards the preloaded
/// indices in `self` are used to lookup all exports on the
/// resulting instance.
pub fn instantiate(
&self,
mut store: impl wasmtime::AsContextMut<Data = _T>,
) -> wasmtime::Result<MyWorld> {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate(&mut store)?;
self.indices.load(&mut store, &instance)
}
}
impl<_T: Send + 'static> MyWorldPre<_T> {
/// Same as [`Self::instantiate`], except with `async`.
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut<Data = _T>,
) -> wasmtime::Result<MyWorld> {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
}
}
/// Auto-generated bindings for index of the exports of
/// `my-world`.
///
/// This is an implementation detail of [`MyWorldPre`] and can
/// be constructed if needed as well.
///
/// For more information see [`MyWorld`] as well.
#[derive(Clone)]
pub struct MyWorldIndices {
interface0: exports::foo::foo::variants::GuestIndices,
}
/// Auto-generated bindings for an instance a component which
/// implements the world `my-world`.
///
/// This structure can be created through a number of means
/// depending on your requirements and what you have on hand:
///
/// * The most convenient way is to use
/// [`MyWorld::instantiate`] which only needs a
/// [`Store`], [`Component`], and [`Linker`].
///
/// * Alternatively you can create a [`MyWorldPre`] ahead of
/// time with a [`Component`] to front-load string lookups
/// of exports once instead of per-instantiation. This
/// method then uses [`MyWorldPre::instantiate`] to
/// create a [`MyWorld`].
///
/// * If you've instantiated the instance yourself already
/// then you can use [`MyWorld::new`].
///
/// These methods are all equivalent to one another and move
/// around the tradeoff of what work is performed when.
///
/// [`Store`]: wasmtime::Store
/// [`Component`]: wasmtime::component::Component
/// [`Linker`]: wasmtime::component::Linker
pub struct MyWorld {
interface0: exports::foo::foo::variants::Guest,
}
const _: () = {
impl MyWorldIndices {
/// Creates a new copy of `MyWorldIndices` bindings which can then
/// be used to instantiate into a particular store.
///
/// This method may fail if the component does not have the
/// required exports.
pub fn new<_T>(
_instance_pre: &wasmtime::component::InstancePre<_T>,
) -> wasmtime::Result<Self> {
let _component = _instance_pre.component();
let _instance_type = _instance_pre.instance_type();
let interface0 = exports::foo::foo::variants::GuestIndices::new(
_instance_pre,
)?;
Ok(MyWorldIndices { interface0 })
}
/// Uses the indices stored in `self` to load an instance
/// of [`MyWorld`] from the instance provided.
///
/// Note that at this time this method will additionally
/// perform type-checks of all exports.
pub fn load(
&self,
mut store: impl wasmtime::AsContextMut,
instance: &wasmtime::component::Instance,
) -> wasmtime::Result<MyWorld> {
let _ = &mut store;
let _instance = instance;
let interface0 = self.interface0.load(&mut store, &_instance)?;
Ok(MyWorld { interface0 })
}
}
impl MyWorld {
/// Convenience wrapper around [`MyWorldPre::new`] and
/// [`MyWorldPre::instantiate`].
pub fn instantiate<_T>(
store: impl wasmtime::AsContextMut<Data = _T>,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result<MyWorld> {
let pre = linker.instantiate_pre(component)?;
MyWorldPre::new(pre)?.instantiate(store)
}
/// Convenience wrapper around [`MyWorldIndices::new`] and
/// [`MyWorldIndices::load`].
pub fn new(
mut store: impl wasmtime::AsContextMut,
instance: &wasmtime::component::Instance,
) -> wasmtime::Result<MyWorld> {
let indices = MyWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
/// Convenience wrapper around [`MyWorldPre::new`] and
/// [`MyWorldPre::instantiate_async`].
pub async fn instantiate_async<_T>(
store: impl wasmtime::AsContextMut<Data = _T>,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result<MyWorld>
where
_T: Send,
{
let pre = linker.instantiate_pre(component)?;
MyWorldPre::new(pre)?.instantiate_async(store).await
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: foo::foo::variants::HostWithStore<T> + Send,
for<'a> D::Data<'a>: foo::foo::variants::Host + Send,
T: 'static + Send,
{
foo::foo::variants::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
}
pub fn foo_foo_variants(&self) -> &exports::foo::foo::variants::Guest {
&self.interface0
}
}
};
pub mod foo {
pub mod foo {
#[allow(clippy::all)]
pub mod variants {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(enum)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum E1 {
#[component(name = "a")]
A,
}
impl ::core::fmt::Debug for E1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
E1::A => f.debug_tuple("E1::A").finish(),
}
}
}
const _: () = {
assert!(1 == < E1 as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < E1 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct Empty {
#[component(name = "a")]
pub a: u32,
}
impl ::core::fmt::Debug for Empty {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("Empty").field("a", &self.a).finish()
}
}
const _: () = {
assert!(4 == < Empty as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < Empty as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone)]
pub enum V1 {
#[component(name = "a")]
A,
#[component(name = "c")]
C(E1),
#[component(name = "d")]
D(wasmtime::component::__internal::String),
#[component(name = "e")]
E(Empty),
#[component(name = "f")]
F,
#[component(name = "g")]
G(u32),
}
impl ::core::fmt::Debug for V1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
V1::A => f.debug_tuple("V1::A").finish(),
V1::C(e) => f.debug_tuple("V1::C").field(e).finish(),
V1::D(e) => f.debug_tuple("V1::D").field(e).finish(),
V1::E(e) => f.debug_tuple("V1::E").field(e).finish(),
V1::F => f.debug_tuple("V1::F").finish(),
V1::G(e) => f.debug_tuple("V1::G").field(e).finish(),
}
}
}
const _: () = {
assert!(12 == < V1 as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V1 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts1 {
#[component(name = "a")]
A(i32),
#[component(name = "b")]
B(f32),
}
impl ::core::fmt::Debug for Casts1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts1::A(e) => f.debug_tuple("Casts1::A").field(e).finish(),
Casts1::B(e) => f.debug_tuple("Casts1::B").field(e).finish(),
}
}
}
const _: () = {
assert!(8 == < Casts1 as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < Casts1 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts2 {
#[component(name = "a")]
A(f64),
#[component(name = "b")]
B(f32),
}
impl ::core::fmt::Debug for Casts2 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts2::A(e) => f.debug_tuple("Casts2::A").field(e).finish(),
Casts2::B(e) => f.debug_tuple("Casts2::B").field(e).finish(),
}
}
}
const _: () = {
assert!(16 == < Casts2 as wasmtime::component::ComponentType >::SIZE32);
assert!(8 == < Casts2 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts3 {
#[component(name = "a")]
A(f64),
#[component(name = "b")]
B(u64),
}
impl ::core::fmt::Debug for Casts3 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts3::A(e) => f.debug_tuple("Casts3::A").field(e).finish(),
Casts3::B(e) => f.debug_tuple("Casts3::B").field(e).finish(),
}
}
}
const _: () = {
assert!(16 == < Casts3 as wasmtime::component::ComponentType >::SIZE32);
assert!(8 == < Casts3 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts4 {
#[component(name = "a")]
A(u32),
#[component(name = "b")]
B(i64),
}
impl ::core::fmt::Debug for Casts4 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts4::A(e) => f.debug_tuple("Casts4::A").field(e).finish(),
Casts4::B(e) => f.debug_tuple("Casts4::B").field(e).finish(),
}
}
}
const _: () = {
assert!(16 == < Casts4 as wasmtime::component::ComponentType >::SIZE32);
assert!(8 == < Casts4 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts5 {
#[component(name = "a")]
A(f32),
#[component(name = "b")]
B(i64),
}
impl ::core::fmt::Debug for Casts5 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts5::A(e) => f.debug_tuple("Casts5::A").field(e).finish(),
Casts5::B(e) => f.debug_tuple("Casts5::B").field(e).finish(),
}
}
}
const _: () = {
assert!(16 == < Casts5 as wasmtime::component::ComponentType >::SIZE32);
assert!(8 == < Casts5 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts6 {
#[component(name = "a")]
A((f32, u32)),
#[component(name = "b")]
B((u32, u32)),
}
impl ::core::fmt::Debug for Casts6 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts6::A(e) => f.debug_tuple("Casts6::A").field(e).finish(),
Casts6::B(e) => f.debug_tuple("Casts6::B").field(e).finish(),
}
}
}
const _: () = {
assert!(12 == < Casts6 as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < Casts6 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(enum)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum MyErrno {
#[component(name = "bad1")]
Bad1,
#[component(name = "bad2")]
Bad2,
}
impl MyErrno {
pub fn name(&self) -> &'static str {
match self {
MyErrno::Bad1 => "bad1",
MyErrno::Bad2 => "bad2",
}
}
pub fn message(&self) -> &'static str {
match self {
MyErrno::Bad1 => "",
MyErrno::Bad2 => "",
}
}
}
impl ::core::fmt::Debug for MyErrno {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("MyErrno")
.field("code", &(*self as i32))
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
impl ::core::fmt::Display for MyErrno {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
write!(f, "{} (error {})", self.name(), * self as i32)
}
}
impl ::core::error::Error for MyErrno {}
const _: () = {
assert!(1 == < MyErrno as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < MyErrno as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone)]
pub struct IsClone {
#[component(name = "v1")]
pub v1: V1,
}
impl ::core::fmt::Debug for IsClone {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("IsClone").field("v1", &self.v1).finish()
}
}
const _: () = {
assert!(12 == < IsClone as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < IsClone as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait HostWithStore<T>: wasmtime::component::HasData + Send {
fn e1_arg(
host: wasmtime::component::Access<T, Self>,
x: E1,
) -> impl ::core::future::Future<Output = ()> + Send;
fn e1_result(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = E1> + Send;
fn v1_arg(
host: wasmtime::component::Access<T, Self>,
x: V1,
) -> impl ::core::future::Future<Output = ()> + Send;
fn v1_result(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = V1> + Send;
fn bool_arg(
host: wasmtime::component::Access<T, Self>,
x: bool,
) -> impl ::core::future::Future<Output = ()> + Send;
fn bool_result(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = bool> + Send;
fn option_arg(
host: wasmtime::component::Access<T, Self>,
a: Option<bool>,
b: Option<(u32,)>,
c: Option<u32>,
d: Option<E1>,
e: Option<f32>,
g: Option<Option<bool>>,
) -> impl ::core::future::Future<Output = ()> + Send;
fn option_result(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<
Output = (
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
> + Send;
fn casts(
host: wasmtime::component::Access<T, Self>,
a: Casts1,
b: Casts2,
c: Casts3,
d: Casts4,
e: Casts5,
f: Casts6,
) -> impl ::core::future::Future<
Output = (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),
> + Send;
fn result_arg(
host: wasmtime::component::Access<T, Self>,
a: Result<(), ()>,
b: Result<(), E1>,
c: Result<E1, ()>,
d: Result<(u32,), (u32,)>,
e: Result<u32, V1>,
f: Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
) -> impl ::core::future::Future<Output = ()> + Send;
fn result_result(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<
Output = (
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
> + Send;
fn return_result_sugar(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = Result<i32, MyErrno>> + Send;
fn return_result_sugar2(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = Result<(), MyErrno>> + Send;
fn return_result_sugar3(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<
Output = Result<MyErrno, MyErrno>,
> + Send;
fn return_result_sugar4(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<
Output = Result<(i32, u32), MyErrno>,
> + Send;
fn return_option_sugar(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = Option<i32>> + Send;
fn return_option_sugar2(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = Option<MyErrno>> + Send;
fn result_simple(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = Result<u32, i32>> + Send;
fn is_clone_arg(
host: wasmtime::component::Access<T, Self>,
a: IsClone,
) -> impl ::core::future::Future<Output = ()> + Send;
fn is_clone_return(
host: wasmtime::component::Access<T, Self>,
) -> impl ::core::future::Future<Output = IsClone> + Send;
}
pub trait Host: Send {}
impl<_T: Host + ?Sized + Send> Host for &mut _T {}
pub fn add_to_linker_instance<T, D>(
inst: &mut wasmtime::component::LinkerInstance<'_, T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore<T>,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
inst.func_wrap_async(
"e1-arg",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (arg0,): (E1,)| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::e1_arg(host, arg0).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"e1-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::e1_result(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"v1-arg",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (arg0,): (V1,)| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::v1_arg(host, arg0).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"v1-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::v1_result(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"bool-arg",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (bool,)|
{
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::bool_arg(host, arg0).await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"bool-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::bool_result(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"option-arg",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(
arg0,
arg1,
arg2,
arg3,
arg4,
arg5,
): (
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
)|
{
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<
T,
>>::option_arg(host, arg0, arg1, arg2, arg3, arg4, arg5)
.await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"option-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::option_result(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"casts",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(
arg0,
arg1,
arg2,
arg3,
arg4,
arg5,
): (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6)|
{
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<
T,
>>::casts(host, arg0, arg1, arg2, arg3, arg4, arg5)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"result-arg",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(
arg0,
arg1,
arg2,
arg3,
arg4,
arg5,
): (
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
)|
{
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<
T,
>>::result_arg(host, arg0, arg1, arg2, arg3, arg4, arg5)
.await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"result-result",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::result_result(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-result-sugar",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_result_sugar(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-result-sugar2",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_result_sugar2(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-result-sugar3",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_result_sugar3(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-result-sugar4",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_result_sugar4(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-option-sugar",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_option_sugar(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"return-option-sugar2",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::return_option_sugar2(host)
.await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"result-simple",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::result_simple(host).await;
Ok((r,))
})
},
)?;
inst.func_wrap_async(
"is-clone-arg",
move |
mut caller: wasmtime::StoreContextMut<'_, T>,
(arg0,): (IsClone,)|
{
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::is_clone_arg(host, arg0)
.await;
Ok(r)
})
},
)?;
inst.func_wrap_async(
"is-clone-return",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
wasmtime::component::__internal::Box::new(async move {
let access_cx = wasmtime::AsContextMut::as_context_mut(
&mut caller,
);
let host = wasmtime::component::Access::<
T,
D,
>::new(access_cx, host_getter);
let r = <D as HostWithStore<T>>::is_clone_return(host).await;
Ok((r,))
})
},
)?;
Ok(())
}
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
D: HostWithStore<T>,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/variants")?;
add_to_linker_instance::<T, D>(&mut inst, host_getter)
}
}
}
}
pub mod exports {
pub mod foo {
pub mod foo {
#[allow(clippy::all)]
pub mod variants {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(enum)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum E1 {
#[component(name = "a")]
A,
}
impl ::core::fmt::Debug for E1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
E1::A => f.debug_tuple("E1::A").finish(),
}
}
}
const _: () = {
assert!(1 == < E1 as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < E1 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct Empty {
#[component(name = "a")]
pub a: u32,
}
impl ::core::fmt::Debug for Empty {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("Empty").field("a", &self.a).finish()
}
}
const _: () = {
assert!(
4 == < Empty as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < Empty as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone)]
pub enum V1 {
#[component(name = "a")]
A,
#[component(name = "c")]
C(E1),
#[component(name = "d")]
D(wasmtime::component::__internal::String),
#[component(name = "e")]
E(Empty),
#[component(name = "f")]
F,
#[component(name = "g")]
G(u32),
}
impl ::core::fmt::Debug for V1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
V1::A => f.debug_tuple("V1::A").finish(),
V1::C(e) => f.debug_tuple("V1::C").field(e).finish(),
V1::D(e) => f.debug_tuple("V1::D").field(e).finish(),
V1::E(e) => f.debug_tuple("V1::E").field(e).finish(),
V1::F => f.debug_tuple("V1::F").finish(),
V1::G(e) => f.debug_tuple("V1::G").field(e).finish(),
}
}
}
const _: () = {
assert!(12 == < V1 as wasmtime::component::ComponentType >::SIZE32);
assert!(4 == < V1 as wasmtime::component::ComponentType >::ALIGN32);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts1 {
#[component(name = "a")]
A(i32),
#[component(name = "b")]
B(f32),
}
impl ::core::fmt::Debug for Casts1 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts1::A(e) => f.debug_tuple("Casts1::A").field(e).finish(),
Casts1::B(e) => f.debug_tuple("Casts1::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
8 == < Casts1 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < Casts1 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts2 {
#[component(name = "a")]
A(f64),
#[component(name = "b")]
B(f32),
}
impl ::core::fmt::Debug for Casts2 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts2::A(e) => f.debug_tuple("Casts2::A").field(e).finish(),
Casts2::B(e) => f.debug_tuple("Casts2::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
16 == < Casts2 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
8 == < Casts2 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts3 {
#[component(name = "a")]
A(f64),
#[component(name = "b")]
B(u64),
}
impl ::core::fmt::Debug for Casts3 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts3::A(e) => f.debug_tuple("Casts3::A").field(e).finish(),
Casts3::B(e) => f.debug_tuple("Casts3::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
16 == < Casts3 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
8 == < Casts3 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts4 {
#[component(name = "a")]
A(u32),
#[component(name = "b")]
B(i64),
}
impl ::core::fmt::Debug for Casts4 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts4::A(e) => f.debug_tuple("Casts4::A").field(e).finish(),
Casts4::B(e) => f.debug_tuple("Casts4::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
16 == < Casts4 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
8 == < Casts4 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts5 {
#[component(name = "a")]
A(f32),
#[component(name = "b")]
B(i64),
}
impl ::core::fmt::Debug for Casts5 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts5::A(e) => f.debug_tuple("Casts5::A").field(e).finish(),
Casts5::B(e) => f.debug_tuple("Casts5::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
16 == < Casts5 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
8 == < Casts5 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(variant)]
#[derive(Clone, Copy)]
pub enum Casts6 {
#[component(name = "a")]
A((f32, u32)),
#[component(name = "b")]
B((u32, u32)),
}
impl ::core::fmt::Debug for Casts6 {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
match self {
Casts6::A(e) => f.debug_tuple("Casts6::A").field(e).finish(),
Casts6::B(e) => f.debug_tuple("Casts6::B").field(e).finish(),
}
}
}
const _: () = {
assert!(
12 == < Casts6 as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < Casts6 as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(enum)]
#[derive(Clone, Copy, Eq, PartialEq)]
#[repr(u8)]
pub enum MyErrno {
#[component(name = "bad1")]
Bad1,
#[component(name = "bad2")]
Bad2,
}
impl MyErrno {
pub fn name(&self) -> &'static str {
match self {
MyErrno::Bad1 => "bad1",
MyErrno::Bad2 => "bad2",
}
}
pub fn message(&self) -> &'static str {
match self {
MyErrno::Bad1 => "",
MyErrno::Bad2 => "",
}
}
}
impl ::core::fmt::Debug for MyErrno {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("MyErrno")
.field("code", &(*self as i32))
.field("name", &self.name())
.field("message", &self.message())
.finish()
}
}
impl ::core::fmt::Display for MyErrno {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
write!(f, "{} (error {})", self.name(), * self as i32)
}
}
impl ::core::error::Error for MyErrno {}
const _: () = {
assert!(
1 == < MyErrno as wasmtime::component::ComponentType >::SIZE32
);
assert!(
1 == < MyErrno as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone)]
pub struct IsClone {
#[component(name = "v1")]
pub v1: V1,
}
impl ::core::fmt::Debug for IsClone {
fn fmt(
&self,
f: &mut ::core::fmt::Formatter<'_>,
) -> ::core::fmt::Result {
f.debug_struct("IsClone").field("v1", &self.v1).finish()
}
}
const _: () = {
assert!(
12 == < IsClone as wasmtime::component::ComponentType >::SIZE32
);
assert!(
4 == < IsClone as wasmtime::component::ComponentType >::ALIGN32
);
};
#[derive(Clone)]
pub struct Guest {
e1_arg: wasmtime::component::Func,
e1_result: wasmtime::component::Func,
v1_arg: wasmtime::component::Func,
v1_result: wasmtime::component::Func,
bool_arg: wasmtime::component::Func,
bool_result: wasmtime::component::Func,
option_arg: wasmtime::component::Func,
option_result: wasmtime::component::Func,
casts: wasmtime::component::Func,
result_arg: wasmtime::component::Func,
result_result: wasmtime::component::Func,
return_result_sugar: wasmtime::component::Func,
return_result_sugar2: wasmtime::component::Func,
return_result_sugar3: wasmtime::component::Func,
return_result_sugar4: wasmtime::component::Func,
return_option_sugar: wasmtime::component::Func,
return_option_sugar2: wasmtime::component::Func,
result_simple: wasmtime::component::Func,
is_clone_arg: wasmtime::component::Func,
is_clone_return: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
e1_arg: wasmtime::component::ComponentExportIndex,
e1_result: wasmtime::component::ComponentExportIndex,
v1_arg: wasmtime::component::ComponentExportIndex,
v1_result: wasmtime::component::ComponentExportIndex,
bool_arg: wasmtime::component::ComponentExportIndex,
bool_result: wasmtime::component::ComponentExportIndex,
option_arg: wasmtime::component::ComponentExportIndex,
option_result: wasmtime::component::ComponentExportIndex,
casts: wasmtime::component::ComponentExportIndex,
result_arg: wasmtime::component::ComponentExportIndex,
result_result: wasmtime::component::ComponentExportIndex,
return_result_sugar: wasmtime::component::ComponentExportIndex,
return_result_sugar2: wasmtime::component::ComponentExportIndex,
return_result_sugar3: wasmtime::component::ComponentExportIndex,
return_result_sugar4: wasmtime::component::ComponentExportIndex,
return_option_sugar: wasmtime::component::ComponentExportIndex,
return_option_sugar2: wasmtime::component::ComponentExportIndex,
result_simple: wasmtime::component::ComponentExportIndex,
is_clone_arg: wasmtime::component::ComponentExportIndex,
is_clone_return: wasmtime::component::ComponentExportIndex,
}
impl GuestIndices {
/// Constructor for [`GuestIndices`] which takes a
/// [`Component`](wasmtime::component::Component) as input and can be executed
/// before instantiation.
///
/// This constructor can be used to front-load string lookups to find exports
/// within a component.
pub fn new<_T>(
_instance_pre: &wasmtime::component::InstancePre<_T>,
) -> wasmtime::Result<GuestIndices> {
let instance = _instance_pre
.component()
.get_export_index(None, "foo:foo/variants")
.ok_or_else(|| {
wasmtime::format_err!(
"no exported instance named `foo:foo/variants`"
)
})?;
let mut lookup = move |name: &str| {
_instance_pre
.component()
.get_export_index(Some(&instance), name)
.ok_or_else(|| {
wasmtime::format_err!(
"instance export `foo:foo/variants` does \
not have export `{name}`"
)
})
};
let _ = &mut lookup;
let e1_arg = lookup("e1-arg")?;
let e1_result = lookup("e1-result")?;
let v1_arg = lookup("v1-arg")?;
let v1_result = lookup("v1-result")?;
let bool_arg = lookup("bool-arg")?;
let bool_result = lookup("bool-result")?;
let option_arg = lookup("option-arg")?;
let option_result = lookup("option-result")?;
let casts = lookup("casts")?;
let result_arg = lookup("result-arg")?;
let result_result = lookup("result-result")?;
let return_result_sugar = lookup("return-result-sugar")?;
let return_result_sugar2 = lookup("return-result-sugar2")?;
let return_result_sugar3 = lookup("return-result-sugar3")?;
let return_result_sugar4 = lookup("return-result-sugar4")?;
let return_option_sugar = lookup("return-option-sugar")?;
let return_option_sugar2 = lookup("return-option-sugar2")?;
let result_simple = lookup("result-simple")?;
let is_clone_arg = lookup("is-clone-arg")?;
let is_clone_return = lookup("is-clone-return")?;
Ok(GuestIndices {
e1_arg,
e1_result,
v1_arg,
v1_result,
bool_arg,
bool_result,
option_arg,
option_result,
casts,
result_arg,
result_result,
return_result_sugar,
return_result_sugar2,
return_result_sugar3,
return_result_sugar4,
return_option_sugar,
return_option_sugar2,
result_simple,
is_clone_arg,
is_clone_return,
})
}
pub fn load(
&self,
mut store: impl wasmtime::AsContextMut,
instance: &wasmtime::component::Instance,
) -> wasmtime::Result<Guest> {
let _instance = instance;
let _instance_pre = _instance.instance_pre(&store);
let _instance_type = _instance_pre.instance_type();
let mut store = store.as_context_mut();
let _ = &mut store;
let e1_arg = *_instance
.get_typed_func::<(E1,), ()>(&mut store, &self.e1_arg)?
.func();
let e1_result = *_instance
.get_typed_func::<(), (E1,)>(&mut store, &self.e1_result)?
.func();
let v1_arg = *_instance
.get_typed_func::<(&V1,), ()>(&mut store, &self.v1_arg)?
.func();
let v1_result = *_instance
.get_typed_func::<(), (V1,)>(&mut store, &self.v1_result)?
.func();
let bool_arg = *_instance
.get_typed_func::<(bool,), ()>(&mut store, &self.bool_arg)?
.func();
let bool_result = *_instance
.get_typed_func::<
(),
(bool,),
>(&mut store, &self.bool_result)?
.func();
let option_arg = *_instance
.get_typed_func::<
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
(),
>(&mut store, &self.option_arg)?
.func();
let option_result = *_instance
.get_typed_func::<
(),
(
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
),
>(&mut store, &self.option_result)?
.func();
let casts = *_instance
.get_typed_func::<
(Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),
((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),),
>(&mut store, &self.casts)?
.func();
let result_arg = *_instance
.get_typed_func::<
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, &V1>,
Result<&str, &[u8]>,
),
(),
>(&mut store, &self.result_arg)?
.func();
let result_result = *_instance
.get_typed_func::<
(),
(
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
),
>(&mut store, &self.result_result)?
.func();
let return_result_sugar = *_instance
.get_typed_func::<
(),
(Result<i32, MyErrno>,),
>(&mut store, &self.return_result_sugar)?
.func();
let return_result_sugar2 = *_instance
.get_typed_func::<
(),
(Result<(), MyErrno>,),
>(&mut store, &self.return_result_sugar2)?
.func();
let return_result_sugar3 = *_instance
.get_typed_func::<
(),
(Result<MyErrno, MyErrno>,),
>(&mut store, &self.return_result_sugar3)?
.func();
let return_result_sugar4 = *_instance
.get_typed_func::<
(),
(Result<(i32, u32), MyErrno>,),
>(&mut store, &self.return_result_sugar4)?
.func();
let return_option_sugar = *_instance
.get_typed_func::<
(),
(Option<i32>,),
>(&mut store, &self.return_option_sugar)?
.func();
let return_option_sugar2 = *_instance
.get_typed_func::<
(),
(Option<MyErrno>,),
>(&mut store, &self.return_option_sugar2)?
.func();
let result_simple = *_instance
.get_typed_func::<
(),
(Result<u32, i32>,),
>(&mut store, &self.result_simple)?
.func();
let is_clone_arg = *_instance
.get_typed_func::<
(&IsClone,),
(),
>(&mut store, &self.is_clone_arg)?
.func();
let is_clone_return = *_instance
.get_typed_func::<
(),
(IsClone,),
>(&mut store, &self.is_clone_return)?
.func();
Ok(Guest {
e1_arg,
e1_result,
v1_arg,
v1_result,
bool_arg,
bool_result,
option_arg,
option_result,
casts,
result_arg,
result_result,
return_result_sugar,
return_result_sugar2,
return_result_sugar3,
return_result_sugar4,
return_option_sugar,
return_option_sugar2,
result_simple,
is_clone_arg,
is_clone_return,
})
}
}
impl Guest {
pub fn func_e1_arg(
&self,
) -> wasmtime::component::TypedFunc<(E1,), ()> {
unsafe {
wasmtime::component::TypedFunc::<
(E1,),
(),
>::new_unchecked(self.e1_arg)
}
}
pub async fn call_e1_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: E1,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_e1_arg();
let () = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(())
}
pub fn func_e1_result(
&self,
) -> wasmtime::component::TypedFunc<(), (E1,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(E1,),
>::new_unchecked(self.e1_result)
}
}
pub async fn call_e1_result<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<E1>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_e1_result();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_v1_arg(
&self,
) -> wasmtime::component::TypedFunc<(V1,), ()> {
unsafe {
wasmtime::component::TypedFunc::<
(V1,),
(),
>::new_unchecked(self.v1_arg)
}
}
pub async fn call_v1_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: V1,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_v1_arg();
let () = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(())
}
pub fn func_v1_result(
&self,
) -> wasmtime::component::TypedFunc<(), (V1,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(V1,),
>::new_unchecked(self.v1_result)
}
}
pub async fn call_v1_result<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<V1>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_v1_result();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_bool_arg(
&self,
) -> wasmtime::component::TypedFunc<(bool,), ()> {
unsafe {
wasmtime::component::TypedFunc::<
(bool,),
(),
>::new_unchecked(self.bool_arg)
}
}
pub async fn call_bool_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: bool,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_bool_arg();
let () = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(())
}
pub fn func_bool_result(
&self,
) -> wasmtime::component::TypedFunc<(), (bool,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(bool,),
>::new_unchecked(self.bool_result)
}
}
pub async fn call_bool_result<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<bool>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_bool_result();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_option_arg(
&self,
) -> wasmtime::component::TypedFunc<
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
(),
> {
unsafe {
wasmtime::component::TypedFunc::<
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
(),
>::new_unchecked(self.option_arg)
}
}
pub async fn call_option_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: Option<bool>,
arg1: Option<(u32,)>,
arg2: Option<u32>,
arg3: Option<E1>,
arg4: Option<f32>,
arg5: Option<Option<bool>>,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_option_arg();
let () = callee
.call_concurrent(
accessor,
(arg0, arg1, arg2, arg3, arg4, arg5),
)
.await?;
Ok(())
}
pub fn func_option_result(
&self,
) -> wasmtime::component::TypedFunc<
(),
(
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
),
>::new_unchecked(self.option_result)
}
}
pub async fn call_option_result<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<
(
Option<bool>,
Option<(u32,)>,
Option<u32>,
Option<E1>,
Option<f32>,
Option<Option<bool>>,
),
>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_option_result();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_casts(
&self,
) -> wasmtime::component::TypedFunc<
(Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),
((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),),
> {
unsafe {
wasmtime::component::TypedFunc::<
(Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),
((Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),),
>::new_unchecked(self.casts)
}
}
pub async fn call_casts<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: Casts1,
arg1: Casts2,
arg2: Casts3,
arg3: Casts4,
arg4: Casts5,
arg5: Casts6,
) -> wasmtime::Result<
(Casts1, Casts2, Casts3, Casts4, Casts5, Casts6),
>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_casts();
let (ret0,) = callee
.call_concurrent(
accessor,
(arg0, arg1, arg2, arg3, arg4, arg5),
)
.await?;
Ok(ret0)
}
pub fn func_result_arg(
&self,
) -> wasmtime::component::TypedFunc<
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
(),
> {
unsafe {
wasmtime::component::TypedFunc::<
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
(),
>::new_unchecked(self.result_arg)
}
}
pub async fn call_result_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: Result<(), ()>,
arg1: Result<(), E1>,
arg2: Result<E1, ()>,
arg3: Result<(u32,), (u32,)>,
arg4: Result<u32, V1>,
arg5: Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_result_arg();
let () = callee
.call_concurrent(
accessor,
(arg0, arg1, arg2, arg3, arg4, arg5),
)
.await?;
Ok(())
}
pub fn func_result_result(
&self,
) -> wasmtime::component::TypedFunc<
(),
(
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
),
>::new_unchecked(self.result_result)
}
}
pub async fn call_result_result<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<
(
Result<(), ()>,
Result<(), E1>,
Result<E1, ()>,
Result<(u32,), (u32,)>,
Result<u32, V1>,
Result<
wasmtime::component::__internal::String,
wasmtime::component::__internal::Vec<u8>,
>,
),
>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_result_result();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_result_sugar(
&self,
) -> wasmtime::component::TypedFunc<(), (Result<i32, MyErrno>,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Result<i32, MyErrno>,),
>::new_unchecked(self.return_result_sugar)
}
}
pub async fn call_return_result_sugar<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Result<i32, MyErrno>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_result_sugar();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_result_sugar2(
&self,
) -> wasmtime::component::TypedFunc<(), (Result<(), MyErrno>,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Result<(), MyErrno>,),
>::new_unchecked(self.return_result_sugar2)
}
}
pub async fn call_return_result_sugar2<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Result<(), MyErrno>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_result_sugar2();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_result_sugar3(
&self,
) -> wasmtime::component::TypedFunc<
(),
(Result<MyErrno, MyErrno>,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Result<MyErrno, MyErrno>,),
>::new_unchecked(self.return_result_sugar3)
}
}
pub async fn call_return_result_sugar3<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Result<MyErrno, MyErrno>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_result_sugar3();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_result_sugar4(
&self,
) -> wasmtime::component::TypedFunc<
(),
(Result<(i32, u32), MyErrno>,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Result<(i32, u32), MyErrno>,),
>::new_unchecked(self.return_result_sugar4)
}
}
pub async fn call_return_result_sugar4<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Result<(i32, u32), MyErrno>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_result_sugar4();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_option_sugar(
&self,
) -> wasmtime::component::TypedFunc<(), (Option<i32>,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Option<i32>,),
>::new_unchecked(self.return_option_sugar)
}
}
pub async fn call_return_option_sugar<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Option<i32>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_option_sugar();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_return_option_sugar2(
&self,
) -> wasmtime::component::TypedFunc<(), (Option<MyErrno>,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Option<MyErrno>,),
>::new_unchecked(self.return_option_sugar2)
}
}
pub async fn call_return_option_sugar2<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Option<MyErrno>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_return_option_sugar2();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_result_simple(
&self,
) -> wasmtime::component::TypedFunc<(), (Result<u32, i32>,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(Result<u32, i32>,),
>::new_unchecked(self.result_simple)
}
}
pub async fn call_result_simple<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<Result<u32, i32>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_result_simple();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_is_clone_arg(
&self,
) -> wasmtime::component::TypedFunc<(IsClone,), ()> {
unsafe {
wasmtime::component::TypedFunc::<
(IsClone,),
(),
>::new_unchecked(self.is_clone_arg)
}
}
pub async fn call_is_clone_arg<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: IsClone,
) -> wasmtime::Result<()>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_is_clone_arg();
let () = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(())
}
pub fn func_is_clone_return(
&self,
) -> wasmtime::component::TypedFunc<(), (IsClone,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(IsClone,),
>::new_unchecked(self.is_clone_return)
}
}
pub async fn call_is_clone_return<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<IsClone>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_is_clone_return();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
}
}
}
}
}