From 5568eb4409f886b0cb894b04c520b792ade187cc Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 10 Sep 2021 10:56:36 -0400 Subject: [PATCH] Extra activity in hello/print/print_display --- rustbyexample/hello/print_display2.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rustbyexample/hello/print_display2.rs b/rustbyexample/hello/print_display2.rs index 4bb58ee..0260116 100644 --- a/rustbyexample/hello/print_display2.rs +++ b/rustbyexample/hello/print_display2.rs @@ -21,6 +21,18 @@ impl fmt::Display for Point2D { } } +#[derive(Debug)] +struct Complex { + real: f64, + imag: f64, +} + +impl fmt::Display for Complex { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} + {}i", self.real, self.imag) + } +} + fn main() { let minmax = MinMax(0, 14); @@ -42,4 +54,13 @@ fn main() { println!("Compare points:"); println!("Display: {}", point); println!("Debug: {:?}", point); + + let cmplx = Complex { + real: 3.3, + imag: 7.2, + }; + + println!("Compare complexes:"); + println!("Display: {}", cmplx); + println!("Debug: {:?}", cmplx); }