From de02f070493e5de71114b505121b1670cffbe9c2 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 31 Aug 2016 10:31:28 -0400 Subject: [PATCH] Done with 1.2.2 activities --- rustbyexample/0122/src/main.rs | 18 ++++++++++++++++++ rustbyexample/0122/src/structure.rs | 9 --------- 2 files changed, 18 insertions(+), 9 deletions(-) delete mode 100644 rustbyexample/0122/src/structure.rs diff --git a/rustbyexample/0122/src/main.rs b/rustbyexample/0122/src/main.rs index 6d3e2f8..c0009fd 100644 --- a/rustbyexample/0122/src/main.rs +++ b/rustbyexample/0122/src/main.rs @@ -21,6 +21,18 @@ impl fmt::Display for Point2 { } } +#[derive(Debug)] +struct Complex { + real: f64, + imag: f64, +} + +impl fmt::Display for Complex { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "real: {}, imag: {}", self.real, self.imag) + } +} + fn main() { let minmax = MinMax(0, 14); @@ -40,4 +52,10 @@ fn main() { println!("Compare points:"); println!("Display: {}", point); println!("Debug: {:?}", point); + + let compl = Complex { real: 3.3, imag: 7.2 }; + + println!("Compare complex:"); + println!("Display: {}", compl); + println!("Debug: {:?}", compl); } diff --git a/rustbyexample/0122/src/structure.rs b/rustbyexample/0122/src/structure.rs deleted file mode 100644 index 5602401..0000000 --- a/rustbyexample/0122/src/structure.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::fmt; - -struct Structure(i32); - -impl fmt::Display for Structure { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0); - } -}