Skip to content

Commit

Permalink
console dbg!
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile committed Oct 20, 2021
1 parent 3cda16f commit 2013f39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/console/src/dbg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// A macro similar to [`dbg!`].
///
/// See the [stdlib documentation][std::dbg] to learn more. This macro calls `console.log`
/// instead of `eprintln!`
#[macro_export]
macro_rules! dbg {
() => {
$crate::log!(::std::format!("[{}:{}]", ::std::file!(), ::std::line!()));
};
($val:expr $(,)?) => {
// Use of `match` here is intentional because it affects the lifetimes
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
$crate::log!(::std::format!("[{}:{}] {} =", ::std::file!(), ::std::line!(), ::std::stringify!($val)), &tmp);
tmp
}
}
};
($($val:expr),+ $(,)?) => {
($($crate::dbg!($val)),+,)
};
}
1 change: 1 addition & 0 deletions crates/console/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![deny(missing_docs, missing_debug_implementations)]

mod counter;
mod dbg;
#[doc(hidden)]
pub mod externs;
mod macros;
Expand Down

0 comments on commit 2013f39

Please sign in to comment.