From 898dc38ec153709929d2513fb9d040dd2c1ce0fe Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 19 Mar 2021 21:23:03 +0100 Subject: [PATCH] =?UTF-8?q?Better=20debug=20representations=20=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/geom/angle.rs | 3 ++- src/geom/gen.rs | 8 +++++++- src/geom/length.rs | 3 ++- src/geom/linear.rs | 2 +- src/geom/point.rs | 2 +- src/geom/size.rs | 2 +- src/geom/spec.rs | 8 +++++++- src/layout/shaping.rs | 2 +- 8 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/geom/angle.rs b/src/geom/angle.rs index a0e2877a2..938141ee3 100644 --- a/src/geom/angle.rs +++ b/src/geom/angle.rs @@ -68,7 +68,8 @@ impl Display for Angle { impl Debug for Angle { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - Display::fmt(self, f) + let unit = AngularUnit::Deg; + write!(f, "{:?}{:?}", self.to_unit(unit), unit) } } diff --git a/src/geom/gen.rs b/src/geom/gen.rs index 8723ea99c..c80cc21b4 100644 --- a/src/geom/gen.rs +++ b/src/geom/gen.rs @@ -1,7 +1,7 @@ use super::*; /// A container with a main and cross component. -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Default, Copy, Clone, Eq, PartialEq)] pub struct Gen { /// The main component. pub main: T, @@ -58,6 +58,12 @@ impl Switch for Gen { } } +impl Debug for Gen { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "Gen({:?}, {:?})", self.main, self.cross) + } +} + /// The two generic layouting axes. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum GenAxis { diff --git a/src/geom/length.rs b/src/geom/length.rs index bc8368105..419da5c37 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -120,7 +120,8 @@ impl Display for Length { impl Debug for Length { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - Display::fmt(self, f) + let unit = LengthUnit::Pt; + write!(f, "{}{}", self.to_unit(unit), unit) } } diff --git a/src/geom/linear.rs b/src/geom/linear.rs index 05990096c..54ff71e66 100644 --- a/src/geom/linear.rs +++ b/src/geom/linear.rs @@ -40,7 +40,7 @@ impl Display for Linear { impl Debug for Linear { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - Display::fmt(self, f) + write!(f, "{:?} + {:?}", self.rel, self.abs) } } diff --git a/src/geom/point.rs b/src/geom/point.rs index 0faa781c8..cf8bc1a9b 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -55,7 +55,7 @@ impl Switch for Point { impl Debug for Point { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "({}, {})", self.x, self.y) + write!(f, "Point({:?}, {:?})", self.x, self.y) } } diff --git a/src/geom/size.rs b/src/geom/size.rs index caba3d8b7..67e5643d6 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -78,7 +78,7 @@ impl Switch for Size { impl Debug for Size { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "({} x {})", self.width, self.height) + write!(f, "Size({:?}, {:?})", self.width, self.height) } } diff --git a/src/geom/spec.rs b/src/geom/spec.rs index c61f9526c..510bac84a 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -1,7 +1,7 @@ use super::*; /// A container with a horizontal and vertical component. -#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] +#[derive(Default, Copy, Clone, Eq, PartialEq)] pub struct Spec { /// The horizontal component. pub horizontal: T, @@ -74,6 +74,12 @@ impl Switch for Spec { } } +impl Debug for Spec { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "Spec({:?}, {:?})", self.horizontal, self.vertical) + } +} + /// The two specific layouting axes. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum SpecAxis { diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index 141fa10e9..1b769db7d 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -54,7 +54,7 @@ impl Shaped { impl Debug for Shaped { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "Shaped({})", self.text) + Debug::fmt(&self.text, f) } }