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 `w`.
///
/// This structure is created through [`WPre::new`] which
/// takes a [`InstancePre`](wasmtime::component::InstancePre) that
/// has been created through a [`Linker`](wasmtime::component::Linker).
///
/// For more information see [`W`] as well.
pub struct WPre<T: 'static> {
instance_pre: wasmtime::component::InstancePre<T>,
indices: WIndices,
}
impl<T: 'static> Clone for WPre<T> {
fn clone(&self) -> Self {
Self {
instance_pre: self.instance_pre.clone(),
indices: self.indices.clone(),
}
}
}
impl<_T: 'static> WPre<_T> {
/// Creates a new copy of `WPre` 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 = WIndices::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 [`W`] 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<W> {
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> WPre<_T> {
/// Same as [`Self::instantiate`], except with `async`.
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut<Data = _T>,
) -> wasmtime::Result<W> {
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
/// `w`.
///
/// This is an implementation detail of [`WPre`] and can
/// be constructed if needed as well.
///
/// For more information see [`W`] as well.
#[derive(Clone)]
pub struct WIndices {
interface0: exports::foo::foo::simple_export::GuestIndices,
interface1: exports::foo::foo::export_using_import::GuestIndices,
interface2: exports::foo::foo::export_using_export1::GuestIndices,
interface3: exports::foo::foo::export_using_export2::GuestIndices,
}
/// Auto-generated bindings for an instance a component which
/// implements the world `w`.
///
/// 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
/// [`W::instantiate`] which only needs a
/// [`Store`], [`Component`], and [`Linker`].
///
/// * Alternatively you can create a [`WPre`] ahead of
/// time with a [`Component`] to front-load string lookups
/// of exports once instead of per-instantiation. This
/// method then uses [`WPre::instantiate`] to
/// create a [`W`].
///
/// * If you've instantiated the instance yourself already
/// then you can use [`W::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 W {
interface0: exports::foo::foo::simple_export::Guest,
interface1: exports::foo::foo::export_using_import::Guest,
interface2: exports::foo::foo::export_using_export1::Guest,
interface3: exports::foo::foo::export_using_export2::Guest,
}
const _: () = {
impl WIndices {
/// Creates a new copy of `WIndices` 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::simple_export::GuestIndices::new(
_instance_pre,
)?;
let interface1 = exports::foo::foo::export_using_import::GuestIndices::new(
_instance_pre,
)?;
let interface2 = exports::foo::foo::export_using_export1::GuestIndices::new(
_instance_pre,
)?;
let interface3 = exports::foo::foo::export_using_export2::GuestIndices::new(
_instance_pre,
)?;
Ok(WIndices {
interface0,
interface1,
interface2,
interface3,
})
}
/// Uses the indices stored in `self` to load an instance
/// of [`W`] 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<W> {
let _ = &mut store;
let _instance = instance;
let interface0 = self.interface0.load(&mut store, &_instance)?;
let interface1 = self.interface1.load(&mut store, &_instance)?;
let interface2 = self.interface2.load(&mut store, &_instance)?;
let interface3 = self.interface3.load(&mut store, &_instance)?;
Ok(W {
interface0,
interface1,
interface2,
interface3,
})
}
}
impl W {
/// Convenience wrapper around [`WPre::new`] and
/// [`WPre::instantiate`].
pub fn instantiate<_T>(
store: impl wasmtime::AsContextMut<Data = _T>,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result<W> {
let pre = linker.instantiate_pre(component)?;
WPre::new(pre)?.instantiate(store)
}
/// Convenience wrapper around [`WIndices::new`] and
/// [`WIndices::load`].
pub fn new(
mut store: impl wasmtime::AsContextMut,
instance: &wasmtime::component::Instance,
) -> wasmtime::Result<W> {
let indices = WIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
/// Convenience wrapper around [`WPre::new`] and
/// [`WPre::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<W>
where
_T: Send,
{
let pre = linker.instantiate_pre(component)?;
WPre::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::transitive_import::HostWithStore<T> + Send,
for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send,
T: 'static + Send,
{
foo::foo::transitive_import::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
}
pub fn foo_foo_simple_export(&self) -> &exports::foo::foo::simple_export::Guest {
&self.interface0
}
pub fn foo_foo_export_using_import(
&self,
) -> &exports::foo::foo::export_using_import::Guest {
&self.interface1
}
pub fn foo_foo_export_using_export1(
&self,
) -> &exports::foo::foo::export_using_export1::Guest {
&self.interface2
}
pub fn foo_foo_export_using_export2(
&self,
) -> &exports::foo::foo::export_using_export2::Guest {
&self.interface3
}
}
};
pub mod foo {
pub mod foo {
#[allow(clippy::all)]
pub mod transitive_import {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
pub enum Y {}
pub trait HostYWithStore<T>: wasmtime::component::HasData {
fn drop(
accessor: &wasmtime::component::Accessor<T, Self>,
rep: wasmtime::component::Resource<Y>,
) -> impl ::core::future::Future<Output = wasmtime::Result<()>> + Send
where
Self: Sized;
}
pub trait HostY {}
impl<_T: HostY + ?Sized + Send> HostY for &mut _T {}
pub trait HostWithStore<
T,
>: wasmtime::component::HasData + HostYWithStore<T> + Send {}
impl<H: ?Sized, T> HostWithStore<T> for H
where
H: wasmtime::component::HasData + HostYWithStore<T> + Send,
{}
pub trait Host: HostY + 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.resource_concurrent(
"y",
wasmtime::component::ResourceType::host::<Y>(),
move |caller: &wasmtime::component::Accessor<T>, rep| {
wasmtime::component::__internal::Box::pin(async move {
let accessor = &caller.with_getter::<D>(host_getter);
wasmtime::ToWasmtimeResult::to_wasmtime_result(
HostYWithStore::<
T,
>::drop(
accessor,
wasmtime::component::Resource::new_own(rep),
)
.await,
)
})
},
)?;
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/transitive-import")?;
add_to_linker_instance::<T, D>(&mut inst, host_getter)
}
}
}
}
pub mod exports {
pub mod foo {
pub mod foo {
#[allow(clippy::all)]
pub mod simple_export {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
pub type A = wasmtime::component::ResourceAny;
pub struct GuestA<'a> {
funcs: &'a Guest,
}
#[derive(Clone)]
pub struct Guest {
constructor_a_constructor: wasmtime::component::Func,
static_a_static_a: wasmtime::component::Func,
method_a_method_a: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
constructor_a_constructor: wasmtime::component::ComponentExportIndex,
static_a_static_a: wasmtime::component::ComponentExportIndex,
method_a_method_a: 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/simple-export")
.ok_or_else(|| {
wasmtime::format_err!(
"no exported instance named `foo:foo/simple-export`"
)
})?;
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/simple-export` does \
not have export `{name}`"
)
})
};
let _ = &mut lookup;
let constructor_a_constructor = lookup("[constructor]a")?;
let static_a_static_a = lookup("[static]a.static-a")?;
let method_a_method_a = lookup("[method]a.method-a")?;
Ok(GuestIndices {
constructor_a_constructor,
static_a_static_a,
method_a_method_a,
})
}
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 constructor_a_constructor = *_instance
.get_typed_func::<
(),
(wasmtime::component::ResourceAny,),
>(&mut store, &self.constructor_a_constructor)?
.func();
let static_a_static_a = *_instance
.get_typed_func::<
(),
(u32,),
>(&mut store, &self.static_a_static_a)?
.func();
let method_a_method_a = *_instance
.get_typed_func::<
(wasmtime::component::ResourceAny,),
(u32,),
>(&mut store, &self.method_a_method_a)?
.func();
Ok(Guest {
constructor_a_constructor,
static_a_static_a,
method_a_method_a,
})
}
}
impl Guest {
pub fn a(&self) -> GuestA<'_> {
GuestA { funcs: self }
}
}
impl GuestA<'_> {
pub fn func_constructor(
&self,
) -> wasmtime::component::TypedFunc<
(),
(wasmtime::component::ResourceAny,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(wasmtime::component::ResourceAny,),
>::new_unchecked(self.funcs.constructor_a_constructor)
}
}
pub async fn call_constructor<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<wasmtime::component::ResourceAny>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_constructor();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_static_a(
&self,
) -> wasmtime::component::TypedFunc<(), (u32,)> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(u32,),
>::new_unchecked(self.funcs.static_a_static_a)
}
}
pub async fn call_static_a<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<u32>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_static_a();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_method_a(
&self,
) -> wasmtime::component::TypedFunc<
(wasmtime::component::ResourceAny,),
(u32,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(wasmtime::component::ResourceAny,),
(u32,),
>::new_unchecked(self.funcs.method_a_method_a)
}
}
pub async fn call_method_a<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: wasmtime::component::ResourceAny,
) -> wasmtime::Result<u32>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_method_a();
let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(ret0)
}
}
}
#[allow(clippy::all)]
pub mod export_using_import {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
pub type Y = super::super::super::super::foo::foo::transitive_import::Y;
pub type A = wasmtime::component::ResourceAny;
pub struct GuestA<'a> {
funcs: &'a Guest,
}
#[derive(Clone)]
pub struct Guest {
constructor_a_constructor: wasmtime::component::Func,
static_a_static_a: wasmtime::component::Func,
method_a_method_a: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
constructor_a_constructor: wasmtime::component::ComponentExportIndex,
static_a_static_a: wasmtime::component::ComponentExportIndex,
method_a_method_a: 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/export-using-import")
.ok_or_else(|| {
wasmtime::format_err!(
"no exported instance named `foo:foo/export-using-import`"
)
})?;
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/export-using-import` does \
not have export `{name}`"
)
})
};
let _ = &mut lookup;
let constructor_a_constructor = lookup("[constructor]a")?;
let static_a_static_a = lookup("[static]a.static-a")?;
let method_a_method_a = lookup("[method]a.method-a")?;
Ok(GuestIndices {
constructor_a_constructor,
static_a_static_a,
method_a_method_a,
})
}
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 constructor_a_constructor = *_instance
.get_typed_func::<
(wasmtime::component::Resource<Y>,),
(wasmtime::component::ResourceAny,),
>(&mut store, &self.constructor_a_constructor)?
.func();
let static_a_static_a = *_instance
.get_typed_func::<
(),
(wasmtime::component::Resource<Y>,),
>(&mut store, &self.static_a_static_a)?
.func();
let method_a_method_a = *_instance
.get_typed_func::<
(
wasmtime::component::ResourceAny,
wasmtime::component::Resource<Y>,
),
(wasmtime::component::Resource<Y>,),
>(&mut store, &self.method_a_method_a)?
.func();
Ok(Guest {
constructor_a_constructor,
static_a_static_a,
method_a_method_a,
})
}
}
impl Guest {
pub fn a(&self) -> GuestA<'_> {
GuestA { funcs: self }
}
}
impl GuestA<'_> {
pub fn func_constructor(
&self,
) -> wasmtime::component::TypedFunc<
(wasmtime::component::Resource<Y>,),
(wasmtime::component::ResourceAny,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(wasmtime::component::Resource<Y>,),
(wasmtime::component::ResourceAny,),
>::new_unchecked(self.funcs.constructor_a_constructor)
}
}
pub async fn call_constructor<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: wasmtime::component::Resource<Y>,
) -> wasmtime::Result<wasmtime::component::ResourceAny>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_constructor();
let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(ret0)
}
pub fn func_static_a(
&self,
) -> wasmtime::component::TypedFunc<
(),
(wasmtime::component::Resource<Y>,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(wasmtime::component::Resource<Y>,),
>::new_unchecked(self.funcs.static_a_static_a)
}
}
pub async fn call_static_a<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<wasmtime::component::Resource<Y>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_static_a();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
pub fn func_method_a(
&self,
) -> wasmtime::component::TypedFunc<
(
wasmtime::component::ResourceAny,
wasmtime::component::Resource<Y>,
),
(wasmtime::component::Resource<Y>,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(
wasmtime::component::ResourceAny,
wasmtime::component::Resource<Y>,
),
(wasmtime::component::Resource<Y>,),
>::new_unchecked(self.funcs.method_a_method_a)
}
}
pub async fn call_method_a<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: wasmtime::component::ResourceAny,
arg1: wasmtime::component::Resource<Y>,
) -> wasmtime::Result<wasmtime::component::Resource<Y>>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_method_a();
let (ret0,) = callee
.call_concurrent(accessor, (arg0, arg1))
.await?;
Ok(ret0)
}
}
}
#[allow(clippy::all)]
pub mod export_using_export1 {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
pub type A = wasmtime::component::ResourceAny;
pub struct GuestA<'a> {
funcs: &'a Guest,
}
#[derive(Clone)]
pub struct Guest {
constructor_a_constructor: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
constructor_a_constructor: 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/export-using-export1")
.ok_or_else(|| {
wasmtime::format_err!(
"no exported instance named `foo:foo/export-using-export1`"
)
})?;
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/export-using-export1` does \
not have export `{name}`"
)
})
};
let _ = &mut lookup;
let constructor_a_constructor = lookup("[constructor]a")?;
Ok(GuestIndices {
constructor_a_constructor,
})
}
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 constructor_a_constructor = *_instance
.get_typed_func::<
(),
(wasmtime::component::ResourceAny,),
>(&mut store, &self.constructor_a_constructor)?
.func();
Ok(Guest { constructor_a_constructor })
}
}
impl Guest {
pub fn a(&self) -> GuestA<'_> {
GuestA { funcs: self }
}
}
impl GuestA<'_> {
pub fn func_constructor(
&self,
) -> wasmtime::component::TypedFunc<
(),
(wasmtime::component::ResourceAny,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(),
(wasmtime::component::ResourceAny,),
>::new_unchecked(self.funcs.constructor_a_constructor)
}
}
pub async fn call_constructor<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
) -> wasmtime::Result<wasmtime::component::ResourceAny>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_constructor();
let (ret0,) = callee.call_concurrent(accessor, ()).await?;
Ok(ret0)
}
}
}
#[allow(clippy::all)]
pub mod export_using_export2 {
#[allow(unused_imports)]
use wasmtime::component::__internal::Box;
pub type A = super::super::super::super::exports::foo::foo::export_using_export1::A;
pub type B = wasmtime::component::ResourceAny;
pub struct GuestB<'a> {
funcs: &'a Guest,
}
#[derive(Clone)]
pub struct Guest {
constructor_b_constructor: wasmtime::component::Func,
}
#[derive(Clone)]
pub struct GuestIndices {
constructor_b_constructor: 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/export-using-export2")
.ok_or_else(|| {
wasmtime::format_err!(
"no exported instance named `foo:foo/export-using-export2`"
)
})?;
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/export-using-export2` does \
not have export `{name}`"
)
})
};
let _ = &mut lookup;
let constructor_b_constructor = lookup("[constructor]b")?;
Ok(GuestIndices {
constructor_b_constructor,
})
}
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 constructor_b_constructor = *_instance
.get_typed_func::<
(wasmtime::component::ResourceAny,),
(wasmtime::component::ResourceAny,),
>(&mut store, &self.constructor_b_constructor)?
.func();
Ok(Guest { constructor_b_constructor })
}
}
impl Guest {
pub fn b(&self) -> GuestB<'_> {
GuestB { funcs: self }
}
}
impl GuestB<'_> {
pub fn func_constructor(
&self,
) -> wasmtime::component::TypedFunc<
(wasmtime::component::ResourceAny,),
(wasmtime::component::ResourceAny,),
> {
unsafe {
wasmtime::component::TypedFunc::<
(wasmtime::component::ResourceAny,),
(wasmtime::component::ResourceAny,),
>::new_unchecked(self.funcs.constructor_b_constructor)
}
}
pub async fn call_constructor<_T, _D>(
&self,
accessor: &wasmtime::component::Accessor<_T, _D>,
arg0: wasmtime::component::ResourceAny,
) -> wasmtime::Result<wasmtime::component::ResourceAny>
where
_T: Send,
_D: wasmtime::component::HasData,
{
let callee = self.func_constructor();
let (ret0,) = callee.call_concurrent(accessor, (arg0,)).await?;
Ok(ret0)
}
}
}
}
}
}