firedbg_lib/
lib.rs

1//! ## FireDBG Support Library
2//!
3//! ### `fire::dbg!`
4//!
5//! This macro allows you to capture the value of a variable via runtime inspection in FireDBG.
6//!
7//! Usage example:
8//!
9//! ```
10//! use firedbg_lib::fire;
11//!
12//! fn some_fn(v: i32) -> i32 {
13//!     fire::dbg!(v) + 1
14//! }
15//!
16//! fn other_fn(v: i32) -> i32 {
17//!     fire::dbg!("arg_v", v) + 1
18//! }
19//! ```
20//!
21//! Which `fire::dbg!(v)` would expand to `__firedbg_trace__("v", v)` when compiled under debug mode.
22//! The label could be customized, which `fire::dbg!("arg_v", v)` would expand to `__firedbg_trace__("arg_v", v)`.
23//! In release mode, it would expand to an expression passing through the value, i.e. `{ v }`.
24//!
25//! Note that the function passes through the ownership of the variable, just like the [`std::dbg!`](https://doc.rust-lang.org/std/macro.dbg.html) macro.
26//!
27//! ```ignore
28//! fn __firedbg_trace__<T>(name: &'static str, v: T) -> T { v }
29//! ```
30pub mod fire {
31    #[macro_export]
32    #[cfg(debug_assertions)]
33    macro_rules! dbg {
34        ($t:expr, $v:expr) => {
35            firedbg_lib::__firedbg_trace__($t, $v);
36        };
37        ($v:expr) => {
38            firedbg_lib::__firedbg_trace__(std::stringify!($v), $v);
39        };
40    }
41
42    #[macro_export]
43    #[cfg(not(debug_assertions))]
44    macro_rules! dbg {
45        ($t:expr, $v:expr) => {{
46            $v
47        }};
48        ($v:expr) => {{
49            $v
50        }};
51    }
52
53    pub use dbg;
54}
55
56#[cfg(debug_assertions)]
57#[allow(unused_variables)]
58pub fn __firedbg_trace__<T>(name: &'static str, v: T) -> T {
59    v
60}