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); - } -}