# Rust E0277: type doesn't implement Display

> Fix Rust E0277 when a type cannot be formatted with {} because it does not implement std::fmt::Display.

HTML: https://rustprint.com/errors/doesnt-implement-display/

Rust reports E0277 when code requires a trait that the type does not implement. With `{}` formatting, the required trait is `std::fmt::Display`.

**A custom struct used with {} without a Display implementation**

```rust
struct Info {
    name: &'static str,
}

fn main() {
    let info = Info { name: "Ada" };
    println!("{info}");
}
```

The example above is intentionally rejected by the stable Rust compiler in CI.

## Fix it by implementing Display

If the type is yours and `{}` should produce a deliberate user-facing representation, implement `Display` for it.

**Add Display and format the struct with {}**

```rust
pub struct DisplayInfo {
    pub name: &'static str,
}

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

`Display::fmt` writes the representation into the supplied `Formatter` and returns `fmt::Result`. Once the type implements `Display`, the same representation also powers `.to_string()`.

For the implementation pattern in more detail, see [implement Display for a Rust struct](/format/implement-display/index.md).

## Do you actually want Debug instead?

`{}` and `{:?}` are not interchangeable spellings of the same formatter. `{}` requests `Display`, which is intended for a deliberate user-facing representation. `{:?}` requests `Debug`, which is intended for programmer-facing inspection.

If you only need to inspect your own struct while developing, deriving `Debug` and using `{:?}` may be the appropriate choice. See [Debug vs Display](/debug/debug-vs-display/index.md) before changing the format specifier just to make the error disappear.

## Why E0277 appears here

E0277 is broader than formatting. It means a required trait bound is missing. In this case the formatting placeholder creates that requirement: `{}` needs `Display`, so a type without `Display` cannot be passed to that formatting position.

If the compiler instead says the type does not implement `Debug`, see [E0277: type doesn't implement Debug](/errors/doesnt-implement-debug/index.md).

## Sources

- [Rust error E0277](https://doc.rust-lang.org/stable/error_codes/E0277.html)
- [std::fmt::Display](https://doc.rust-lang.org/std/fmt/trait.Display.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().
- [Debug vs Display in Rust](/debug/debug-vs-display/index.md): Choose between Rust Debug and Display based on programmer-facing inspection versus deliberate user-facing text.
- [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.
