fmt::Display: how a Rust type prints with {}
Answer: The fmt module provides runtime support for the format! family of macros. To use the {} marker, implement the Display trait. The format string must be a string literal so the compiler can check it.
format! and Display
Runtime support for the format! syntax extension lives in this module.
The macro writes formatted arguments into strings at runtime.
Calling to_string uses the Display formatting trait.
The format string has to be a string literal. A variable is not accepted, so the compiler can check the string.
Implementing the trait
Debug output is often not compact or clean, so customizing the appearance is useful.
Implement fmt::Display yourself when you want the {} print marker to look the way you need.
The trait's fmt method must use a specific signature.
See also
Claims
- id: C1 claim: std::fmt supports the format! macro at runtime. source: S1 evidence: "runtime support for the format! syntax extension"
- id: C2 claim: The format string must be a string literal. source: S1 evidence: "this to be a string literal"
- id: C3 claim: Implement Display to customize {} output. source: S2 evidence: "manually implementing fmt::Display"
- id: C4 claim: Display uses the {} print marker. source: S2 evidence: "uses the {} print marker"
Sources
- [S1] std::fmt. Rust Standard Library. https://doc.rust-lang.org/std/fmt/index.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
- [S2] Display. Rust By Example. https://doc.rust-lang.org/rust-by-example/hello/print/print_display.html . License: MIT OR Apache-2.0. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fmt; Rust By Example, Display. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Rust Standard Library, std::fmt; Rust By Example, Display. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust/master/COPYRIGHT). Copyright the Rust Project Developers. MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rust-by-example/master/LICENSE-MIT). Copyright the Rust Project Developers.
Cite this
iinventedlight. 2026. "fmt::Display: how a Rust type prints with {}." iinventedlight Library, iil:note:he8eqh6f, version of 2026-11-23. https://iinventedlight.com/library/notes/rust-display/. License: CC-BY-4.0.
@misc{iil_note_he8eqh6f,
author = {{iinventedlight}},
title = {{fmt::Display: how a Rust type prints with \{\}}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/rust-display/},
note = {Permanent ID iil:note:he8eqh6f. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- rust-display.schema.json (schema; CC-BY-4.0)
- rust-display.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-display.md.