#string #wasm-edge #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

#1320 in Procedural macros

Download history 25/week @ 2024-03-16 4/week @ 2024-03-23 44/week @ 2024-03-30 109/week @ 2024-04-06 24/week @ 2024-04-13 65/week @ 2024-04-20 9/week @ 2024-04-27 8/week @ 2024-05-11 1/week @ 2024-05-18 79/week @ 2024-05-25 35/week @ 2024-06-01 99/week @ 2024-06-08 8/week @ 2024-06-15 4/week @ 2024-06-22

114 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
~35K SLoC