Description
I've been experimenting with ways to provide reusable bits of host functionality and have run into a stumbling block with wasmtime's generated add_to_linker
functions, which take get
closures with types (roughly) like:
get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static
...
where U: Host,
These closures are usually trivial field accesses like |data| &mut data.some_host_impl
, but this is somewhat limiting because you can only return &mut
s borrowing from T
. As a specific example, the wasmtime-wasi WasiView::table
needs to be shared with wasmtime-wasi-http's WasiHttpView::table
, but this currently requires both *View
implementations to use the same concrete type within T
, making the two host implementations uncomposable.
There are some unsafe
approaches to deal with this but I'm wondering if it would be possible to change the add_to_linker
closure signature to permit returning non-ref types, e.g. something that impl
s AsMut<U>
. I've been trying to find a way to do this backward-compatibility but I'm running into the limits of my understanding of closure lifetime