macro_rules! dbg_ref {
($val:expr $(,)?) => { ... };
($($val:expr),+ $(,)?) => { ... };
}Expand description
Similar to the dbg! macro, but inspects values by reference without moving
them. This allows debugging values without transferring ownership, while
showing the underlying value’s type information (not reference types).
This macro uses log::debug! internally, so you must:
- Configure a logger (e.g.,
env_logger) with debug level enabled - Initialize the logger before use
§Key Differences from dbg!
- Returns
()instead of the original value - Requires explicit logger initialization
§Examples
Basic usage with automatic type deduction
use testutils::dbg_ref;
// Must initialize logger first:
// env_logger::builder().filter_level(log::LevelFilter::Debug).init();
let counter = 42;
dbg_ref!(counter); // [DEBUG] counter: i32 = 42
let message = "Hello";
dbg_ref!(message); // [DEBUG] message: &str = "Hello"
let values = vec![(1, "a"), (2, "b")];
dbg_ref!(values); // [DEBUG] values: alloc::vec::Vec<(i32, &str)> = [...]Debugging multiple values
use testutils::dbg_ref;
let width = 30;
let label = "size";
dbg_ref!(width, label);
// Outputs:
// [DEBUG] width: i32 = 30
// [DEBUG] label: &str = "size"§Implementation Notes
- Uses
core::any::type_name_of_valfor type information - Formats output as:
{variable_name}: {type} = {debug_representation} - Multiple arguments generate separate log entries