Coverage Report

Created: 2025-11-20 14:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/src/execution/mod.rs
Line
Count
Source
1
use alloc::vec::Vec;
2
3
use const_interpreter_loop::run_const_span;
4
use store::HaltExecutionError;
5
use value_stack::Stack;
6
7
use crate::execution::assert_validated::UnwrapValidatedExt;
8
use crate::execution::value::Value;
9
use crate::interop::InteropValueList;
10
11
pub(crate) mod assert_validated;
12
pub mod config;
13
pub mod const_interpreter_loop;
14
pub mod error;
15
pub mod interop;
16
mod interpreter_loop;
17
pub mod linker;
18
pub(crate) mod little_endian;
19
pub mod resumable;
20
pub mod store;
21
pub mod value;
22
pub mod value_stack;
23
24
/// Helper function to quickly construct host functions without worrying about wasm to Rust
25
/// type conversion. For reading/writing user data into the current configuration, simply move
26
/// `user_data` into the passed closure.
27
/// # Example
28
/// ```
29
/// use wasm::{validate,  Store, host_function_wrapper, Value, HaltExecutionError};
30
/// fn my_wrapped_host_func(user_data: &mut (), params: Vec<Value>) -> Result<Vec<Value>, HaltExecutionError> {
31
///     host_function_wrapper(params, |(x, y): (u32, i32)| -> Result<u32, HaltExecutionError> {
32
///         let _user_data = user_data;
33
///         Ok(x + (y as u32))
34
///     })
35
/// }
36
/// fn main() {
37
///     let mut store = Store::new(());
38
///     let foo_bar = store.func_alloc_typed::<(u32, i32), u32>(my_wrapped_host_func);
39
/// }
40
/// ```
41
1
pub fn host_function_wrapper<Params: InteropValueList, Results: InteropValueList>(
42
1
    params: Vec<Value>,
43
1
    f: impl FnOnce(Params) -> Result<Results, HaltExecutionError>,
44
1
) -> Result<Vec<Value>, HaltExecutionError> {
45
1
    let params =
46
1
        Params::try_from_values(params.into_iter()).expect("Params match the actual parameters");
47
1
    f(params).map(Results::into_values)
48
1
}