#[wasm_func]
Expand description
Wrap the function to be used with the protocol.
§Arguments
All the arguments of the function should be &[u8]
, no lifetime needed.
§Return type
The return type of the function should be Vec<u8>
or Result<Vec<u8>, E>
where
E: ToString
.
If the function return Vec<u8>
, it will be implicitely wrapped in Ok
.
§Example
use wasm_minimal_protocol::wasm_func;
#[cfg(target_arch = "wasm32")]
wasm_minimal_protocol::initiate_protocol!();
#[cfg_attr(target_arch = "wasm32", wasm_func)]
fn function_one() -> Vec<u8> {
Vec::new()
}
#[cfg_attr(target_arch = "wasm32", wasm_func)]
fn function_two(arg1: &[u8], arg2: &[u8]) -> Result<Vec<u8>, i32> {
Ok(b"Normal message".to_vec())
}
#[cfg_attr(target_arch = "wasm32", wasm_func)]
fn function_three(arg1: &[u8]) -> Result<Vec<u8>, String> {
Err(String::from("Error message"))
}