From dcb6ae6dc14684a670adaffc1c682e48c403a7d9 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sun, 7 May 2023 12:15:37 +0100 Subject: [PATCH] Add a dbg macro to the print utility --- src/print.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/print.rs b/src/print.rs index 26c16a9..fc6d9ac 100644 --- a/src/print.rs +++ b/src/print.rs @@ -49,3 +49,22 @@ macro_rules! eprint { let _ = core::write!($crate::print::StderrPrinter, $($arg)*); }) } + +#[macro_export] +macro_rules! dbg { + () => { + $crate::eprintln!("[{}:{}]", ::core::file!(), ::core::line!()) + }; + ($val:expr $(,)?) => { + match $val { + tmp => { + $crate::eprintln!("[{}:{}] {} = {:#?}", + ::core::file!(), ::core::line!(), ::core::stringify!($val), &tmp); + tmp + } + } + }; + ($($val:expr),+ $(,)?) => { + ($($crate::dbg!($val)),+,) + }; +}