Skip to content

Commit

Permalink
Add an dbg! equivalent to gloo-console (#158)
Browse files Browse the repository at this point in the history
* console dbg!

* fix name

* fmt
  • Loading branch information
ranile authored Oct 24, 2021
1 parent 3cda16f commit 3713988
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/console_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! console {
() => {
$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 @@ -17,6 +17,7 @@
#![deny(missing_docs, missing_debug_implementations)]

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

0 comments on commit 3713988

Please sign in to comment.