Crates.io | uptown_funk |
lib.rs | uptown_funk |
version | 0.1.3 |
source | src |
created_at | 2021-01-26 14:09:32.200604 |
updated_at | 2021-04-08 14:35:43.700285 |
description | Define host functions compatible with Wasmer and Wasmtime |
homepage | |
repository | |
max_upload_size | |
id | 346883 |
size | 54,273 |
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
:
#[host_functions(namespace = "wasi_snapshot_preview1")]
impl WasiState {
async fn fd_pread(&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.