console_web/lib.rs
1#[doc(hidden)]
2pub use web_sys as _web_sys;
3#[doc(hidden)]
4pub use js_sys as _js_sys;
5
6/// This macro works the same as the `println!` from the standard library.
7///
8/// # Examples
9///
10/// ```rust,no_run
11/// console_web::println!("The number 42 is {}", 42);
12/// ```
13#[macro_export]
14macro_rules! println {
15 ($($args:tt)*) => {
16 $crate::_web_sys::console::log_1(&format!($($args)*).into())
17 };
18}
19
20/// This macro works the same as the `eprintln!` from the standard library.
21///
22/// # Examples
23///
24/// ```rust,no_run
25/// console_web::eprintln!("The number 42 is {}", 42);
26/// ```
27#[macro_export]
28macro_rules! eprintln {
29 ($($args:tt)*) => {
30 $crate::_web_sys::console::error_1(&format!($($args)*).into())
31 };
32}
33
34/// This macro works like the `console.log` function in javascript.
35///
36/// # Examples
37///
38/// ```rust,no_run
39/// console_web::log!("a string", 42, true);
40/// ```
41#[macro_export]
42macro_rules! log {
43 ($($args:tt,)*) => {
44 $crate::log!($($args),*)
45 };
46 ($($args:tt),*) => {
47 let mut arr = $crate::_js_sys::Array::new();
48 $(
49 arr.push(&$args.into());
50 )*
51 $crate::_web_sys::console::log(&arr)
52 };
53}
54
55/// This macro works like the `console.error` function in javascript.
56///
57/// # Examples
58///
59/// ```rust,no_run
60/// console_web::error!("a string", 42, true);
61/// ```
62#[macro_export]
63macro_rules! error {
64 ($($args:tt,)*) => {
65 $crate::error!($($args),*)
66 };
67 ($($args:tt),*) => {
68 let mut arr = $crate::_js_sys::Array::new();
69 $(
70 arr.push(&$args.into());
71 )*
72 $crate::_web_sys::console::error(&arr)
73 };
74}