-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
31 lines (25 loc) · 954 Bytes
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
mod custom_error;
mod event;
use custom_error::CustomError;
use wasm_bindgen::{prelude::wasm_bindgen, JsError};
pub use event::Event;
#[wasm_bindgen(js_name = "parseWithStringError")]
pub fn parse_with_string_error(event: &str) -> Result<Event, String> {
let event: Event = serde_json::from_str(event).map_err(|e| e.to_string())?;
Ok(event)
}
#[wasm_bindgen(js_name = "parseWithError")]
pub fn parse_with_error(event: &str) -> Result<Event, JsError> {
let event: Event = serde_json::from_str(event).map_err(|e| JsError::from(e))?;
Ok(event)
}
#[wasm_bindgen(js_name = "parseWithCustomError")]
pub fn parse_with_custom_error(event: &str) -> Result<Event, JsError> {
let event: Event = serde_json::from_str(event).map_err(|e| CustomError::new(e))?;
Ok(event)
}
#[wasm_bindgen(js_name = "parseWithPanic")]
pub fn parse_with_panic(event: &str) -> Event {
let event: Event = serde_json::from_str(event).unwrap();
event
}