macro_rules! cdbg {
(
// shows no location (pretty-print) cdbg![# x];
# $v:expr $(,)?) => { ... };
(# $($v:expr),+ $(,)?) => { ... };
(
// shows no location cdbg![x];
// cdbg![@ x];
$(@)? $v:expr $(,)?) => { ... };
($($v:expr),+ $(,)?) => { ... };
(
// shows the last $n location components cdbg![1@ x];
// ($n=0 no location, $n=1 just the filename)
$n:literal @ $v:expr $(,)?) => { ... };
($n:literal @ $($v:expr),+ $(,)?) => { ... };
($n:literal @) => { ... };
(// (pretty-print) cdbg![1# x];
$n:literal # $v:expr $(,)?) => { ... };
($n:literal # $($v:expr),+ $(,)?) => { ... };
($n:literal #) => { ... };
(
// shows the full path location cdbg![f@ x];
f @ $v:expr $(,)?) => { ... };
(f @ $($v:expr),+ $(,)?) => { ... };
(f @) => { ... };
(// (pretty-print) (equivalent to `dbg!`) cdbg![f # x];
f # $v:expr $(,)?) => { ... };
(f # $($v:expr),+ $(,)?) => { ... };
(f #) => { ... };
(
// shows the full path location in a separate line cdbg![fln@ x];
fln @ $v:expr $(,)?) => { ... };
(fln @ $($v:expr),+ $(,)?) => { ... };
(fln @) => { ... };
(// (pretty-print) cdbg![fln # x];
fln # $v:expr $(,)?) => { ... };
(fln # $($v:expr),+ $(,)?) => { ... };
(fln #) => { ... };
() => { ... };
}
Available on crate feature
std
only.Expand description
c
ustomizable dbg!
macro.
- By default uses
{:?}
instead of{:#?}
for formatting. - By default doesn’t show the location (file, line and column).
- It can show the
$n
last components, instead of the full path.
§Examples
let a = vec![1, 2, 3];
let _ = cdbg![&a];
let _ = cdbg![@ &a];
let _ = cdbg![0@ &a];
// ^-- prints: &a = [1, 2, 3]
let _ = cdbg![1@ &a];
// ^-- prints: [main.rs:6:10] &a = [1, 2, 3]
let _ = cdbg![2@ &a];
// ^-- prints: [src/main.rs:8:10] &a = [1, 2, 3]
let _ = cdbg![f@ &a];
// ^-- prints: [/full/path/.../src/main.rs:10:9] &a = [1, 2, 3]
let _ = cdbg![fln@ &a];
// ^-- prints: [/full/path/.../src/main.rs:12:9]
// &a = [1, 2, 3]
// use `#` for pretty-printing:
let _ = cdbg![# &a];
let _ = cdbg![0# &a]; // same as cdbg![# &a]
let _ = cdbg![1# &a];
let _ = cdbg![f # &a]; // same as `dbg!` macro (notice the required whitespace)
let _ = cdbg![fln # &a]; // same as before, but separates the path in a new line