From 098d91cae08fe82eef35730fa63cea4e23b0e253 Mon Sep 17 00:00:00 2001 From: Eduard Bopp Date: Wed, 17 Jan 2018 17:35:01 +0100 Subject: [PATCH] Remove phantom data from matrix debug output Addresses #295. --- src/core/matrix.rs | 10 +++++++++- tests/core/matrix.rs | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/matrix.rs b/src/core/matrix.rs index e29eff72..34f6b2db 100644 --- a/src/core/matrix.rs +++ b/src/core/matrix.rs @@ -68,7 +68,7 @@ pub type MatrixCross = /// dynamically-sized column vector should be represented as a `Matrix` (given /// some concrete types for `N` and a compatible data storage type `S`). #[repr(C)] -#[derive(Hash, Debug, Clone, Copy)] +#[derive(Hash, Clone, Copy)] pub struct Matrix { /// The data storage that contains all the matrix components and informations about its number /// of rows and column (if needed). @@ -77,6 +77,14 @@ pub struct Matrix { _phantoms: PhantomData<(N, R, C)> } +impl fmt::Debug for Matrix { + fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { + formatter.debug_struct("Matrix") + .field("data", &self.data) + .finish() + } +} + #[cfg(feature = "serde-serialize")] impl Serialize for Matrix where N: Scalar, diff --git a/tests/core/matrix.rs b/tests/core/matrix.rs index 996d1d64..d86cc87e 100644 --- a/tests/core/matrix.rs +++ b/tests/core/matrix.rs @@ -62,6 +62,13 @@ fn iter() { assert!(it.next().is_none()); } +#[test] +fn debug_output_corresponds_to_data_container() { + assert_eq!( + format!("{:?}", Matrix2::new(1.0, 2.0, 3.0, 4.0)), + "Matrix { data: [1, 3, 2, 4] }" + ); +} #[test] fn is_column_major() {