Display
Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value.
Refactoring to Rust
The Display trait is Rust's formatting trait for producing a user-facing textual representation of a value.
- How it is used
- Centralizes user-facing calculator error messages so callers can print specific errors with {}.
- How deep it goes
- Works through fmt, Formatter, write!, variant matching, and the updated error-printing call.
- Examples
- Uses a hello-world Display implementation and calculator errors for invalid input and an empty stack.
- What you can do after
- Apply it via std::fmt to define reusable error messages and print them with eprintln!.
Learn Rust in a Month of Lunches
Display printing formats a Rust value using its user-facing Display formatting behavior.
- How it is used
- Formats values for readable `println!` output and lets custom types control the wording shown to users.
- How deep it goes
- Moves from `{}` and compiler feedback to a worked `Display` implementation; leaves some `Formatter` syntax unexplained.
- Examples
- Uses a failed attempt to print `()`, a custom `Cat` sentence, and cleaner article-application output.
- What you can do after
- Build it from scratch for a struct, then print it with `{}` or turn its output into a `String`.
Read how Learn Rust in a Month of Lunches explains Display →
Rust in Action: Systems programming concepts and techniques
The Display trait is Rust's standard formatting trait for producing a user-facing textual representation of a value.
- How it is used
- Formats custom values for console output, strings, formatted writers, and user-facing error messages.
- How deep it goes
- Defines the fmt contract and demonstrates nested implementations, but leaves Formatter details largely unexplored.
- Examples
- Uses File and FileState formatting plus an UpstreamError enum that reuses Debug output.
- What you can do after
- Build it from scratch by implementing Display for structs, enums, nested fields, and wrapper error types.
Read how Rust in Action: Systems programming concepts and techniques explains Display →
Related concepts
- 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.
- traitkind of · A trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
- toStringproduces · toString is a method or trait operation that returns a textual representation of a value or object.
- slicingimplemented by · Slicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
- use declarationused by · A use declaration is Rust syntax that brings names or items from a module or crate into scope for unqualified access.
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.


