fp_bindgen_support/common/
abi.rs

1pub trait WasmAbi {
2    type AbiType;
3
4    fn to_abi(self) -> Self::AbiType;
5    fn from_abi(value: Self::AbiType) -> Self;
6}
7
8impl WasmAbi for bool {
9    type AbiType = u8;
10
11    #[inline]
12    fn to_abi(self) -> Self::AbiType {
13        if self {
14            1
15        } else {
16            0
17        }
18    }
19
20    #[inline]
21    fn from_abi(value: Self::AbiType) -> Self {
22        value != 0
23    }
24}
25
26macro_rules! identity_wasm_abi {
27    ($ty:ty) => {
28        impl WasmAbi for $ty {
29            type AbiType = $ty;
30
31            #[inline]
32            fn to_abi(self) -> Self::AbiType {
33                self
34            }
35
36            #[inline]
37            fn from_abi(value: Self::AbiType) -> Self {
38                value
39            }
40        }
41    };
42    ($($ty:ty),*) => {
43        $(
44            identity_wasm_abi!($ty);
45        )*
46    }
47}
48
49identity_wasm_abi!((), u8, u16, u32, u64, i8, i16, i32, i64, f32, f64);