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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#[cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "console-debug"
))]
pub use web_sys::console::debug_1 as log;
#[cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "console-error"
))]
pub use web_sys::console::error_1 as log;
#[cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "console-info"
))]
pub use web_sys::console::info_1 as log;
#[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "console-log"))]
pub use web_sys::console::log_1 as log;
#[cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "console-trace"
))]
pub use web_sys::console::trace_1 as log;
#[cfg(all(
target_arch = "wasm32",
target_os = "unknown",
feature = "console-warn"
))]
pub use web_sys::console::warn_1 as log;
#[macro_export]
macro_rules! dbg {
() => {{
#[cfg(any(target_os = "wasi", not(target_arch = "wasm32")))]
std::dbg!();
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
$crate::log(&format!("[{}:{}]", std::file!(), std::line!()).into());
}};
($val: expr $(,)?) => {{
#[cfg(any(target_os = "wasi", not(target_arch = "wasm32")))]
std::dbg!($val);
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
match $val {
tmp => {
$crate::log(&format!("[{}:{}] {} = {:#?}",
std::file!(), std::line!(), std::stringify!($val), &tmp).into());
tmp
}
}
}};
($($val: expr),+ $(,)?) => {{
($($crate::dbg!($val)),+,)
}}
}