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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct I64(i64);
#[wasm_bindgen]
impl I64 {
#[allow(clippy::should_implement_trait)]
pub fn from_str(string: &str) -> Result<I64, JsValue> {
string
.parse::<i64>()
.map_err(|e| JsValue::from_str(&format! {"{:?}", e}))
.map(I64)
}
pub fn to_str(&self) -> String {
format!("{}", self.0)
}
pub fn as_num(&self) -> js_sys::Number {
js_sys::Number::from(self.0 as f64)
}
}
impl From<i64> for I64 {
fn from(v: i64) -> Self {
I64(v)
}
}
impl From<I64> for i64 {
fn from(v: I64) -> Self {
v.0
}
}
#[allow(dead_code, missing_docs)]
pub fn set_panic_hook() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}