Better debug representations 💻

This commit is contained in:
Laurenz 2021-03-19 21:23:03 +01:00
parent 264a7dedd4
commit 898dc38ec1
8 changed files with 22 additions and 8 deletions

View File

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

View File

@ -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<T> {
/// The main component.
pub main: T,
@ -58,6 +58,12 @@ impl<T> Switch for Gen<T> {
}
}
impl<T: Debug> Debug for Gen<T> {
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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -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<T> {
/// The horizontal component.
pub horizontal: T,
@ -74,6 +74,12 @@ impl<T> Switch for Spec<T> {
}
}
impl<T: Debug> Debug for Spec<T> {
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 {

View File

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