1use wasm_bindgen::prelude::*;
5
6#[cfg(feature = "websocket")]
7pub mod websocket;
8
9#[cfg(feature = "crypto")]
10pub mod crypto;
11
12pub mod error;
13
14#[macro_export]
16macro_rules! console_log {
17 ($($t:tt)*) => ($crate::log(&format_args!($($t)*).to_string()))
18}
19
20#[macro_export]
22macro_rules! console_debug {
23 ($($t:tt)*) => ($crate::debug(&format_args!($($t)*).to_string()))
24}
25
26#[macro_export]
28macro_rules! console_info {
29 ($($t:tt)*) => ($crate::info(&format_args!($($t)*).to_string()))
30}
31
32#[macro_export]
34macro_rules! console_warn {
35 ($($t:tt)*) => ($crate::warn(&format_args!($($t)*).to_string()))
36}
37
38#[macro_export]
40macro_rules! console_error {
41 ($($t:tt)*) => ($crate::error(&format_args!($($t)*).to_string()))
42}
43
44#[wasm_bindgen]
45pub fn set_panic_hook() {
46 #[cfg(feature = "console_error_panic_hook")]
53 console_error_panic_hook::set_once();
54}
55
56#[wasm_bindgen]
57extern "C" {
58 #[wasm_bindgen(js_namespace = console)]
59 pub fn log(s: &str);
60
61 #[wasm_bindgen(js_namespace = console)]
62 pub fn debug(s: &str);
63
64 #[wasm_bindgen(js_namespace = console)]
65 pub fn info(s: &str);
66
67 #[wasm_bindgen(js_namespace = console)]
68 pub fn warn(s: &str);
69
70 #[wasm_bindgen(js_namespace = console)]
71 pub fn error(s: &str);
72}
73
74#[cfg(feature = "sleep")]
75pub async fn sleep(ms: i32) -> Result<(), wasm_bindgen::JsValue> {
76 let promise = js_sys::Promise::new(&mut |yes, _| {
77 let win = web_sys::window().expect("no window available!");
78 win.set_timeout_with_callback_and_timeout_and_arguments_0(&yes, ms)
79 .unwrap();
80 });
81 let js_fut = wasm_bindgen_futures::JsFuture::from(promise);
82 js_fut.await?;
83 Ok(())
84}