use wasm_bindgen::prelude::*;
#[cfg(feature = "websocket")]
pub mod websocket;
#[cfg(feature = "crypto")]
pub mod crypto;
pub mod error;
#[macro_export]
macro_rules! console_log {
($($t:tt)*) => ($crate::log(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! console_debug {
($($t:tt)*) => ($crate::debug(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! console_info {
($($t:tt)*) => ($crate::info(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! console_warn {
($($t:tt)*) => ($crate::warn(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! console_error {
($($t:tt)*) => ($crate::error(&format_args!($($t)*).to_string()))
}
#[wasm_bindgen]
pub fn set_panic_hook() {
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str);
#[wasm_bindgen(js_namespace = console)]
pub fn debug(s: &str);
#[wasm_bindgen(js_namespace = console)]
pub fn info(s: &str);
#[wasm_bindgen(js_namespace = console)]
pub fn warn(s: &str);
#[wasm_bindgen(js_namespace = console)]
pub fn error(s: &str);
}
#[cfg(feature = "sleep")]
pub async fn sleep(ms: i32) -> Result<(), wasm_bindgen::JsValue> {
let promise = js_sys::Promise::new(&mut |yes, _| {
let win = web_sys::window().expect("no window available!");
win.set_timeout_with_callback_and_timeout_and_arguments_0(&yes, ms)
.unwrap();
});
let js_fut = wasm_bindgen_futures::JsFuture::from(promise);
js_fut.await?;
Ok(())
}