uptown_funk is a crate that lets you elegantly define Wasm host functions that are compatible with both Wasmtime and Wasmer runtimes.
It consists of a macro and a few structs/traits that let you translate from Wasm primitive types to higher level Rust types, and back.
Lets look at an example of a host function definition using uptown_funk
:
```rust
impl WasiState { async fn fdpread(&mut self, fd: u32, iovs: &mut [IoSliceMut<'>], offset: Filesize) -> (Status, u32) { // ... }
// .. Other functions depending on the WasiState struct.
} ```
The host_function
macro lets us grab any host side struct and use it as state for the Wasm instances.
Instead of dealing with low level pointers + lengths passed from the WebAssembly guests, we can pretend
to receive higher level Rust type (e.g. &mut [IoSliceMut<'_>]
) and the macro is going to create
appropriate wrappers for us. And of course, it correctly works with async
functions on Lunatic.