Debug
Debug is a Rust standard-library formatting trait for producing programmer-oriented representations of values.
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.
Also covered in
What to know first
- RustRust is a statically typed systems programming language designed for performance, concurrency, and memory safety without requiring garbage collection.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
Related concepts
- derive macroimplemented by · A Rust derive attribute requests generated 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.
- traitkind of · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
- println! macroused by · In Rust, println! is a standard-library macro that formats arguments and writes the resulting text followed by a newline to standard output.
Questions about Debug
What is Debug?
Debug is a Rust standard-library formatting trait for producing programmer-oriented representations of values.
Which Manning books explain Debug?
Refactoring to Rust and Learn Rust in a Month of Lunches.
What should I know before learning Debug?
Manning books that teach Debug usually introduce Rust and string first.
What is the difference between Debug and Display?
Debug is a Rust standard-library formatting trait for producing programmer-oriented representations of values. Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value.
What is Debug a kind of?
Debug is a kind of trait. A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
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.

