From cabb0a9eaba750076c808a4987fca6cdd4599e62 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 11 Sep 2021 13:26:27 -0400 Subject: [PATCH] RBE primitives tuples activity 1 --- rustbyexample/primitives/primitives_tuples.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rustbyexample/primitives/primitives_tuples.rs b/rustbyexample/primitives/primitives_tuples.rs index 724b269..105835d 100644 --- a/rustbyexample/primitives/primitives_tuples.rs +++ b/rustbyexample/primitives/primitives_tuples.rs @@ -1,3 +1,5 @@ +use std::fmt; + fn reverse(pair: (i32, bool)) -> (bool, i32) { let (integer, boolean) = pair; (boolean, integer) @@ -6,6 +8,12 @@ fn reverse(pair: (i32, bool)) -> (bool, i32) { #[derive(Debug)] struct Matrix(f32, f32, f32, f32); +impl fmt::Display for Matrix { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "( {} {} )\n( {} {} )", self.0, self.1, self.2, self.3) + } +} + fn main() { let long_tuple = ( 1u8, 2u16, 3u32, 4u64, -1i8, -2i16, -3i32, -4i64, 0.1f32, 0.2f64, 'a', true, @@ -33,4 +41,5 @@ fn main() { let matrix = Matrix(1.1, 1.2, 2.1, 2.2); println!("{:?}", matrix); + println!("{}", matrix); }