Skip to main content

DisplayAsDebug

Derive Macro DisplayAsDebug 

Source
#[derive(DisplayAsDebug)]
Expand description

Derive macro for implementing std::fmt::Display using the existing Debug implementation.

This macro requires that the type already implements Debug. It delegates the Display implementation to the Debug implementation, so both {} and {:?} will produce the same output.

ยงExample

use format_attr::DisplayAsDebug;

#[derive(Debug, DisplayAsDebug)]
struct Value(i32);

let v = Value(42);
assert_eq!(format!("{}", v), "Value(42)");
assert_eq!(format!("{:?}", v), "Value(42)");