macro
dbg! — Inspect a value and keep its result
Inspect an expression through its Debug implementation on stderr and return the evaluated value. Source location and expression text appear in the diagnostic; the exact diagnostic layout is not a stable interface. Non-Copy inputs can be moved; use dbg!(&value) to inspect by borrowing. It is not automatically disabled in release builds. Expression result: type of input expression (one argument). Expected result (not executed): stdout: '21\n'; stderr contains '3 * 7 = 21' Common mistake: Using dbg!(owned_string) and then trying to access the moved binding.
Formal Syntax & Structure
rust syntaxrust
dbg!(expression)Working Example
Example Snippetrust
fn main() { let total = dbg!(3 * 7); println!("{total}");}