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
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(js_namespace = console)]
    pub fn log(str: &str);
    #[wasm_bindgen(js_namespace = console)]
    pub fn error(str: &str);
    #[wasm_bindgen(js_namespace = console)]
    pub fn time(str: &str);
    #[wasm_bindgen(js_namespace = console, js_name = "timeEnd")]
    pub fn time_end(str: &str);
}

#[macro_export]
macro_rules! log {
    ($($tt:tt)*) => {
        $crate::console::log(&format!($($tt)*));
    }
}

#[macro_export]
macro_rules! time {
    ($name:expr => $value:expr) => {{
        $crate::console::time($name);
        let value = $value;
        $crate::console::time_end($name);
        value
    }};
}