gloo_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 gloo_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 macros::*;
29pub use timer::Timer;
30
31#[doc(hidden)]
32pub mod __macro {
33    use gloo_utils::format::JsValueSerdeExt;
34    pub use js_sys::Array;
35    pub use wasm_bindgen::JsValue;
36    use wasm_bindgen::UnwrapThrowExt;
37
38    pub fn table_with_data_and_columns<'a>(
39        data: impl serde::Serialize,
40        columns: impl IntoIterator<Item = &'a str>,
41    ) {
42        let data = <JsValue as JsValueSerdeExt>::from_serde(&data).unwrap_throw();
43        let columns = columns.into_iter().map(JsValue::from_str).collect();
44
45        crate::externs::table_with_data_and_columns(data, columns);
46    }
47}
OSZAR »