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
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
#![no_std]
#[macro_export]
macro_rules! dbg {
// NOTE: We cannot use `concat!` to make a static string as a format argument
// of `eprintln!` because `file!` could contain a `{` or
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
// will be malformed.
() => {
{
use gstd::{debug, prelude::{file, line}};
gstd::debug!("[{}:{}]", gstd::prelude::file!(), gstd::prelude::line!())
}
};
($val:expr $(,)?) => {
{
use gstd::{debug, prelude::{file, line, stringify}};
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
gstd::debug!("[{}:{}] {} = {:#?}",
gstd::prelude::file!(),
gstd::prelude::line!(),
gstd::prelude::stringify!($val),
&tmp);
tmp
}
}
}
};
($($val:expr),+ $(,)?) => {
($(dbg!($val)),+,)
};
}