// Created on savesnippets.com ยท https://savesnippets.com/6z6o9HpftLnll6 use std::fmt; #[derive(Debug)] struct Money { cents: u64, currency: &'static str, } impl fmt::Display for Money { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let dollars = self.cents / 100; let cents = self.cents % 100; write!(f, "{}{}.{:02}", self.currency, dollars, cents) } } fn main() { let price = Money { cents: 4_99, currency: "$" }; println!("{price}"); // $4.99 (uses Display) println!("{price:?}"); // Money { cents: 499, currency: "$" } (Debug) println!("{price:#?}"); // Same, pretty-printed }