pub fn host_function_wrapper<Params: InteropValueList, Results: InteropValueList>(
params: Vec<Value>,
f: impl FnOnce(Params) -> Results,
) -> Vec<Value>
Expand description
Helper function to quickly construct host functions without worrying about wasm to Rust type conversion. For user data, simply move the mutable reference into the passed closure.
ยงExample
use wasm::{validate, RuntimeInstance, host_function_wrapper, Value};
fn my_wrapped_host_func(user_data: &mut (), params: Vec<Value>) -> Vec<Value> {
host_function_wrapper(params, |(x, y): (u32, i32)| -> u32 {
let _user_data = user_data;
x + (y as u32)
})
}
fn main() {
let mut instance = RuntimeInstance::new(());
let foo_bar = instance.add_host_function_typed::<(u32,i32),u32>("foo", "bar", my_wrapped_host_func).unwrap();
}