#![allow(dead_code, deprecated, unused_variables, unused_mut)] use std::fmt; struct Bar { bar: i32, another: String, } impl fmt::Debug for Bar { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Bar") .field("bar", &self.bar) .field("another", &self.another) .field("nonexistent_field", &1) .finish() } } fn main() { assert_eq!( format!("{:?}", Bar { bar : 10, another : "Hello World".to_string() }), r#"Bar { bar: 10, another: "Hello World", nonexistent_field: 1 }"#, ); }