#wasm-edge #string #type #host #macro #data #wasmedge-bindgen

macro wasmedge-bindgen-macro

Pass string, vec and primitive types from host to webassembly

9 releases

0.4.1 Nov 18, 2022
0.4.0 Jul 6, 2022
0.1.14 Jun 16, 2022
0.1.13 Jan 11, 2022
0.1.8 Dec 23, 2021

#1796 in Procedural macros

29 downloads per month

MIT/Apache

22KB
598 lines

About

This crate only export a macro named #[wasmedge_bindgen] that used for retouching exporting functions to make it support more data types.

Data Types

Parameters

You can set the parameters to any one of the following types:

  • Scalar Types: i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, bool, char
  • String
  • Vec: Vec<i8>, Vec<u8>, Vec<i16>, Vec<u16>, Vec<i32>, Vec<u32>, Vec<i64>, Vec<u64>

Return Values

You can set the return values to any one of the following types:

  • Scalar Types: i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, bool, char
  • String
  • Vec: Vec<i8>, Vec<u8>, Vec<i16>, Vec<u16>, Vec<i32>, Vec<u32>, Vec<i64>, Vec<u64>
  • Tuple Type: compounded by any number of the above three types
  • Result: Ok<any one of the above four types>, Err<String>

The only way to tell the host that the error has occurred is to return Err<String> of Result.

Examples

#[wasmedge_bindgen]
pub fn create_line(p1: String, p2: String, desc: String) -> String

#[wasmedge_bindgen]
pub fn lowest_common_multiple(a: i32, b: i32) -> i32

#[wasmedge_bindgen]
pub fn sha3_digest(v: Vec<u8>) -> Vec<u8>

#[wasmedge_bindgen]
pub fn info(v: Vec<u8>) -> Result<(u8, String), String>

Dependencies

~1.5MB
~37K SLoC