1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[doc(hidden)]
pub use web_sys as _web_sys;
#[doc(hidden)]
pub use js_sys as _js_sys;

/// This macro works the same as the `println!` from the standard library.
///
/// # Examples
///
/// ```rust,no_run
/// console_web::println!("The number 42 is {}", 42);
/// ```
#[macro_export]
macro_rules! println {
    ($($args:tt)*) => {
        $crate::_web_sys::console::log_1(&format!($($args)*).into())
    };
}

/// This macro works the same as the `eprintln!` from the standard library.
///
/// # Examples
///
/// ```rust,no_run
/// console_web::eprintln!("The number 42 is {}", 42);
/// ```
#[macro_export]
macro_rules! eprintln {
    ($($args:tt)*) => {
        $crate::_web_sys::console::error_1(&format!($($args)*).into())
    };
}

/// This macro works like the `console.log` function in javascript.
///
/// # Examples
///
/// ```rust,no_run
/// console_web::log!("a string", 42, true);
/// ```
#[macro_export]
macro_rules! log {
    ($($args:tt,)*) => {
        $crate::log!($($args),*)
    };
    ($($args:tt),*) => {
        let mut arr = $crate::_js_sys::Array::new();
        $(
            arr.push(&$args.into());
        )*
        $crate::_web_sys::console::log(&arr)
    };
}

/// This macro works like the `console.error` function in javascript.
///
/// # Examples
///
/// ```rust,no_run
/// console_web::error!("a string", 42, true);
/// ```
#[macro_export]
macro_rules! error {
    ($($args:tt,)*) => {
        $crate::error!($($args),*)
    };
    ($($args:tt),*) => {
        let mut arr = $crate::_js_sys::Array::new();
        $(
            arr.push(&$args.into());
        )*
        $crate::_web_sys::console::error(&arr)
    };
}