Debug
Debug is a Rust standard-library trait for formatting values in programmer-oriented diagnostic representations.
Refactoring to Rust
The Debug trait is a Rust formatting trait for producing developer-oriented representations of values.
- How it is used
- Supports developer-oriented error output when Result values are unwrapped or expected to panic.
- How deep it goes
- Defines developer representation and demonstrates enum derivation, but defers deeper trait details.
- Examples
- Uses a FizzBuzz Error enum with GotNegative, #[derive(Debug)], unwrap(), expect(), and panic output.
- What you can do after
- Apply it via #[derive(Debug)] so Rust errors can be printed by unwrap() and expect().
Learn Rust in a Month of Lunches
Debug is the Rust trait for producing programmer-oriented representations of values.
- How it is used
- Uses programmer-oriented output to inspect values when Display formatting is unavailable or insufficient.
- How deep it goes
- Explains format choices, compiler guidance, pretty output, and derive(Debug), but defers manual fmt implementation.
- Examples
- Uses the unit value (), compiler error E0277, and a User structure to contrast ordinary and pretty Debug output.
- What you can do after
- Apply Debug via println! using {:?}, {:#?}, and #[derive(Debug)] to inspect values.
Related concepts
- traitkind of · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
- println! macroused by · The println! macro is an output operation that formats arguments and writes the resulting text followed by a line terminator to standard output.
- derive macroconfigured by · A Rust derive macro is an attribute that automatically generates implementations of specified traits or related functionality for a type.
- Displaycontrasts with · Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

