Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 22 additions & 36 deletions crates/component-macro/tests/expanded/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
U: foo::foo::chars::Host,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::chars::Host,
T: 'static,
{
foo::foo::chars::add_to_linker(linker, get)?;
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
}
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
Expand All @@ -171,22 +173,25 @@ pub mod foo {
/// A function that returns a character
fn return_char(&mut self) -> char;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host;
impl<_T: Host> Host for &mut _T {
/// A function that accepts a character
fn take_char(&mut self, x: char) -> () {
Host::take_char(*self, x)
}
/// A function that returns a character
fn return_char(&mut self) -> char {
Host::return_char(*self)
}
}
impl<F, T, O> GetHost<T> for F
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host,
T: 'static,
{
type Host = O;
}
pub fn add_to_linker_get_host<T, G: for<'a> GetHost<&'a mut T, Host: Host>>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap(
"take-char",
Expand All @@ -209,25 +214,6 @@ pub mod foo {
)?;
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 {
/// A function that accepts a character
fn take_char(&mut self, x: char) -> () {
Host::take_char(*self, x)
}
/// A function that returns a character
fn return_char(&mut self) -> char {
Host::return_char(*self)
}
}
}
}
}
Expand Down
62 changes: 20 additions & 42 deletions crates/component-macro/tests/expanded/char_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,16 @@ const _: () = {
let indices = TheWorldIndices::new(&instance.instance_pre(&store))?;
indices.load(&mut store, instance)
}
pub fn add_to_linker<T, U>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: Send,
U: foo::foo::chars::Host + Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: foo::foo::chars::Host + Send,
T: 'static + Send,
{
foo::foo::chars::add_to_linker(linker, get)?;
foo::foo::chars::add_to_linker::<T, D>(linker, host_getter)?;
Ok(())
}
pub fn foo_foo_chars(&self) -> &exports::foo::foo::chars::Guest {
Expand All @@ -179,27 +180,24 @@ pub mod foo {
/// A function that returns a character
async fn return_char(&mut self) -> char;
}
pub trait GetHost<
T,
>: Fn(T) -> <Self as GetHost<T>>::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
impl<F, T, O> GetHost<T> for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
impl<_T: Host + Send> Host for &mut _T {
/// A function that accepts a character
async fn take_char(&mut self, x: char) -> () {
Host::take_char(*self, x).await
}
/// A function that returns a character
async fn return_char(&mut self) -> char {
Host::return_char(*self).await
}
}
pub fn add_to_linker_get_host<
T,
G: for<'a> GetHost<&'a mut T, Host: Host + Send>,
>(
pub fn add_to_linker<T, D>(
linker: &mut wasmtime::component::Linker<T>,
host_getter: G,
host_getter: fn(&mut T) -> D::Data<'_>,
) -> wasmtime::Result<()>
where
T: Send,
D: wasmtime::component::HasData,
for<'a> D::Data<'a>: Host,
T: 'static + Send,
{
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap_async(
Expand Down Expand Up @@ -227,26 +225,6 @@ pub mod foo {
)?;
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 + Send,
T: Send,
{
add_to_linker_get_host(linker, get)
}
impl<_T: Host + ?Sized + Send> Host for &mut _T {
/// A function that accepts a character
async fn take_char(&mut self, x: char) -> () {
Host::take_char(*self, x).await
}
/// A function that returns a character
async fn return_char(&mut self) -> char {
Host::return_char(*self).await
}
}
}
}
}
Expand Down
Loading
Loading