Reorganize and clean up the WASM wrapper

This commit is contained in:
Keavon Chambers 2021-09-01 06:10:05 -07:00
parent 699657974a
commit 5675126a89
7 changed files with 217 additions and 176 deletions

View file

@ -0,0 +1,24 @@
use wasm_bindgen::prelude::*;
// The JavaScript `Error` type
#[wasm_bindgen]
extern "C" {
#[derive(Clone, Debug)]
pub type Error;
#[wasm_bindgen(constructor)]
pub fn new(msg: &str) -> Error;
}
/// Takes a string and matches it to its equivalently-named enum variant (useful for simple type translations)
macro_rules! match_string_to_enum {
(match ($e:expr) {$($var:ident),* $(,)?}) => {
match $e {
$(
stringify!($var) => Some($var),
)*
_ => None
}
};
}
pub(crate) use match_string_to_enum;