fmt::Error
RustERRORCriticalFormatting

Formatting error

Quick Answer

Ensure the underlying Write target (String, Vec) does not fail; for custom formatters return Err(fmt::Error) to signal failure.

What this means

Returned by std::fmt::Write implementations when a write to the formatter fails. Rarely seen unless you implement Display or Write manually.

Why it happens
  1. 1Custom fmt::Write implementation signalling failure
  2. 2write! macro returning Err in a Display impl

Fix

Implement Display correctly

Implement Display correctly
use std::fmt;
struct Point(f64, f64);
impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "({}, {})", self.0, self.1)
    }
}

Why this works

Propagate the result of write! via ? or return Ok(()) to satisfy fmt::Result.

Code examples
fmt::Resultrust
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) }
Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Rust errors