Macro gclient::ext::sp_core::wasm_export_functions
macro_rules! wasm_export_functions { ( $( fn $name:ident ( $( $arg_name:ident: $arg_ty:ty ),* $(,)? ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* } )* ) => { ... }; (@IMPL fn $name:ident ( $( $arg_name:ident: $arg_ty:ty ),* ) { $( $fn_impl:tt )* } ) => { ... }; (@IMPL fn $name:ident ( $( $arg_name:ident: $arg_ty:ty ),* ) $( -> $ret_ty:ty )? { $( $fn_impl:tt )* } ) => { ... }; }
Expand description
Macro for exporting functions from wasm in with the expected signature for using it with the wasm executor. This is useful for tests where you need to call a function in wasm.
The input parameters are expected to be SCALE encoded and will be automatically decoded for you. The output value is also SCALE encoded when returned back to the host.
The functions are feature-gated with #[cfg(not(feature = "std"))]
, so they are only available
from within wasm.
ยงExample
wasm_export_functions! {
fn test_in_wasm(value: bool, another_value: Vec<u8>) -> bool {
value && another_value.is_empty()
}
fn without_return_value() {
// do something
}
}