ianaio_console/
lib.rs

1//! The JavaScript's `console` object provides access to the browser's console.
2//! Using the `console` object in Rust/WASM directly is cumbersome as it requires JavaScript glue code.
3//! This crate exists to solve this problem by providing a set of ergonomic Rust APIs to deal
4//! with the browser console.
5//!
6//! # Example
7//!
8//! The following example logs text to the console using `console.log`
9//!
10//! ```no_run, rust
11//! # use wasm_bindgen::JsValue;
12//! use ianaio_console::log;
13//!
14//! let object = JsValue::from("any JsValue can be logged");
15//! log!("text", object)
16//! ```
17
18#![deny(missing_docs, missing_debug_implementations)]
19
20mod console_dbg;
21mod counter;
22#[doc(hidden)]
23pub mod externs;
24mod macros;
25mod timer;
26
27pub use counter::Counter;
28pub use timer::Timer;
29
30#[doc(hidden)]
31pub mod __macro {
32    use ianaio_utils::format::JsValueSerdeExt;
33    pub use js_sys::Array;
34    pub use wasm_bindgen::JsValue;
35    use wasm_bindgen::UnwrapThrowExt;
36
37    pub fn table_with_data_and_columns<'a>(
38        data: impl serde::Serialize,
39        columns: impl IntoIterator<Item = &'a str>,
40    ) {
41        let data = <JsValue as JsValueSerdeExt>::from_serde(&data).unwrap_throw();
42        let columns = columns.into_iter().map(JsValue::from_str).collect();
43
44        crate::externs::table_with_data_and_columns(data, columns);
45    }
46}