-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
61 lines (59 loc) · 1.73 KB
/
lib.rs
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
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "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)),+,)
};
}
#[cfg(feature = "std")]
#[macro_export]
macro_rules! dbg {
// std implementation
() => {
{
eprintln!("[{}:{}]", file!(), line!());
}
};
($val:expr $(,)?) => {
{
eprintln!("[{}:{}] {} = {:?}",
file!(),
line!(),
stringify!($val),
&$val);
$val
}
};
($($val:expr),+ $(,)?) => {
($(dbg!($val)),+,)
};
}