From 60da2e20dceaa1bb13b2c13d416e79755e93f2f3 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 10 Sep 2021 11:18:23 -0400 Subject: [PATCH] RBE hello/print/fmt activity --- rustbyexample/hello/print_fmt.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rustbyexample/hello/print_fmt.rs b/rustbyexample/hello/print_fmt.rs index 49cbd83..9a6c344 100644 --- a/rustbyexample/hello/print_fmt.rs +++ b/rustbyexample/hello/print_fmt.rs @@ -30,6 +30,16 @@ struct Color { blue: u8, } +impl Display for Color { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "RGB ({}, {}, {}) 0x{:02X}{:02X}{:02X}", + self.red, self.green, self.blue, self.red, self.green, self.blue + ) + } +} + fn main() { for city in [ City { @@ -72,6 +82,6 @@ fn main() { ] .iter() { - println!("{:?}", *color); + println!("{}", *color); } }