pub struct DPre<T> {
instance_pre: wasmtime::component::InstancePre<T>,
}
impl<T> Clone for DPre<T> {
fn clone(&self) -> Self {
Self {
instance_pre: self.instance_pre.clone(),
}
}
}
pub struct D {}
const _: () = {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
impl<_T> DPre<_T> {
pub fn new(
instance_pre: wasmtime::component::InstancePre<_T>,
) -> wasmtime::Result<Self> {
let _component = instance_pre.component();
Ok(DPre { instance_pre })
}
pub fn instantiate(
&self,
mut store: impl wasmtime::AsContextMut<Data = _T>,
) -> wasmtime::Result<D> {
let mut store = store.as_context_mut();
let _instance = self.instance_pre.instantiate(&mut store)?;
Ok(D {})
}
pub fn engine(&self) -> &wasmtime::Engine {
self.instance_pre.engine()
}
pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
&self.instance_pre
}
}
impl D {
pub fn instantiate<_T>(
mut store: impl wasmtime::AsContextMut<Data = _T>,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result<D> {
let pre = linker.instantiate_pre(component)?;
DPre::new(pre)?.instantiate(store)
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
U: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host,
{
foo::foo::a::add_to_linker(linker, get)?;
foo::foo::b::add_to_linker(linker, get)?;
foo::foo::c::add_to_linker(linker, get)?;
d::add_to_linker(linker, get)?;
Ok(())
}
}
};
pub mod foo {
pub mod foo {
#[allow(clippy::all)]
pub mod a {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
#[derive(wasmtime::component::ComponentType)]
#[derive(wasmtime::component::Lift)]
#[derive(wasmtime::component::Lower)]
#[component(record)]
#[derive(Clone, Copy)]
pub struct Foo {}
impl core::fmt::Debug for Foo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Foo").finish()
}
}
const _: () = {
assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {
fn a(&mut self) -> Foo;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, O> GetHost<T> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<T>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: impl for<'a> GetHost<&'a mut T>,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/a")?;
inst.func_wrap(
"a",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::a(host);
Ok((r,))
},
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn a(&mut self) -> Foo {
Host::a(*self)
}
}
}
#[allow(clippy::all)]
pub mod b {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
pub type Foo = super::super::super::foo::foo::a::Foo;
const _: () = {
assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {
fn a(&mut self) -> Foo;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, O> GetHost<T> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<T>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: impl for<'a> GetHost<&'a mut T>,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/b")?;
inst.func_wrap(
"a",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::a(host);
Ok((r,))
},
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn a(&mut self) -> Foo {
Host::a(*self)
}
}
}
#[allow(clippy::all)]
pub mod c {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
pub type Foo = super::super::super::foo::foo::b::Foo;
const _: () = {
assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {
fn a(&mut self) -> Foo;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, O> GetHost<T> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<T>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: impl for<'a> GetHost<&'a mut T>,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/c")?;
inst.func_wrap(
"a",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::a(host);
Ok((r,))
},
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn a(&mut self) -> Foo {
Host::a(*self)
}
}
}
}
}
#[allow(clippy::all)]
pub mod d {
#[allow(unused_imports)]
use wasmtime::component::__internal::anyhow;
pub type Foo = super::foo::foo::c::Foo;
const _: () = {
assert!(0 == < Foo as wasmtime::component::ComponentType >::SIZE32);
assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32);
};
pub trait Host {
fn b(&mut self) -> Foo;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
impl<F, T, O> GetHost<T> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
pub fn add_to_linker_get_host<T>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: impl for<'a> GetHost<&'a mut T>,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("d")?;
inst.func_wrap(
"b",
move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| {
let host = &mut host_getter(caller.data_mut());
let r = Host::b(host);
Ok((r,))
},
)?;
Ok(())
}
pub fn add_to_linker<T, U>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
) -> wasmtime::Result<()>
where
U: Host,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized> Host for &mut _T {
fn b(&mut self) -> Foo {
Host::b(*self)
}
}
}