liveBook · Manning

Display

Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value.

How 4 Manning books explain it

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
Uses Display to centralize user-facing error messages in a calculator.
How deep it goes
Walks through implementing fmt with Formatter and write!, including a match over error variants.
Examples
Uses a Hello World type and calculator errors for invalid numbers and empty-stack operations.
What you can do after
Build a Display implementation from scratch and use it to print custom error messages.

Read how Refactoring to Rust explains Display →

Rust Web Development

Display is a Rust formatting trait for representing values in human-readable, user-facing form.

How it is used
Provides readable output for custom values and API errors.
How deep it goes
Walks through implementing fmt with Formatter and write!, including nested fields and enum variants.
Examples
Uses a question with an identifier and optional tags, plus pagination errors for invalid or missing parameters.
What you can do after
Build it from scratch by implementing Display for a custom struct or error enum.

Read how Rust Web Development explains Display →

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 user-facing values and customizes application output.
How deep it goes
Explains formatting and a custom implementation, while leaving the formatter variable and lifetime syntax unexplained.
Examples
Uses a failed unit-value print and a custom Cat with name and age fields.
What you can do after
Build a Display implementation for a custom type and print it with {}.

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 →

What to know first

Related concepts

Questions about Display

What is Display?

Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value.

Which Manning books explain Display?

Refactoring to Rust, Rust Web Development, Learn Rust in a Month of Lunches and Rust in Action: Systems programming concepts and techniques.

What should I know before learning Display?

Manning books that teach Display usually introduce Debug, result type, Rust and vector first.

What is the difference between Display and Debug?

Display is Rust’s standard formatting trait for producing a user-facing textual representation of a value. Debug is a Rust standard-library formatting trait for producing programmer-oriented representations of values.

What is Display a kind of?

Display 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.