# Debug vs Display in Rust

> Choose between Rust Debug and Display based on programmer-facing inspection versus deliberate user-facing text.

HTML: https://rustprint.com/debug/debug-vs-display/

`Display` and `Debug` both format values, but they make different promises. `Display` is a deliberate user-facing representation. `Debug` is for programmer-facing inspection and diagnostics.

**One type with separate Display and Debug representations**

```rust
impl fmt::Display for LabelledPoint {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(formatter, "{},{}", self.x, self.y)
    }
}
```

## Display

`Display` powers `{}`. It cannot be derived because the standard library cannot decide what the one intended user-facing representation of an arbitrary type should be.

Implementing `Display` also gives the type the blanket `ToString` implementation, so implement `Display` rather than implementing `ToString` directly.

Typical uses include text shown to users, concise human-readable identifiers, and labels where the representation is part of the type's public behavior. See [implement Display for a Rust struct](/format/implement-display/index.md) for the focused implementation pattern.

## Debug

`Debug` powers `{:?}`. For ordinary structs and enums, `#[derive(Debug)]` is usually the right starting point.

Its purpose is inspection, so exposing field names and internal structure is normal. That also means it should not be treated as a stable wire format or serialization contract.

## A type can implement both

There is no conflict in implementing both traits with different representations. That is often the useful design.

The `Display` output can stay concise while `Debug` shows enough internal state to diagnose a problem. Code then chooses intentionally between `{value}` and `{value:?}` instead of trying to make one representation serve every audience.

For the full mapping between format suffixes and traits, see [formatting traits](/reference/formatting-traits/index.md).

## Sources

- [Display](https://doc.rust-lang.org/std/fmt/trait.Display.html)
- [Debug](https://doc.rust-lang.org/std/fmt/trait.Debug.html)

## Related RustPrint guides

- [Implement Display for a Rust struct](/format/implement-display/index.md): Implement std::fmt::Display for a Rust struct with Formatter and write!, then use {} formatting and to_string().
- [Rust formatting traits - Display, Debug, hex, binary, and more](/reference/formatting-traits/index.md): Map Rust format syntax such as {}, {:?}, {:x}, {:b}, and {:e} to the std::fmt traits Display, Debug, LowerHex, Binary, and LowerExp.
- [Rust dbg! macro: inspect values with Debug](/debug/inspect-values/index.md): Use Rust dbg! to print expressions to stderr, understand its return and move behavior, and compare compact {:?} with pretty {:#?} Debug output.
- [Rust pretty print a struct with {:#?}](/debug/pretty-debug/index.md): Pretty print Rust structs, enums, maps, and nested values with {:#?}, derive Debug, and understand why Debug output is not a stable serialization format.
