From 8c939fb0543726f772df05780e3fad35c9aae93e Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Sun, 25 Oct 2020 20:20:10 +0100 Subject: [PATCH] Cleanup value by using DebugCustom --- src/value/coords.rs | 10 +++------- src/value/mod.rs | 18 ++++-------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/value/coords.rs b/src/value/coords.rs index 5959e23..4b9f3eb 100644 --- a/src/value/coords.rs +++ b/src/value/coords.rs @@ -3,20 +3,16 @@ use derive_more::*; use serde::{Deserialize, Serialize}; use std::{fmt, str::FromStr}; -#[derive(Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Display)] +#[derive(Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Display, DebugCustom)] pub enum NumWithUnit { #[display(fmt = "{}%", .0)] + #[debug(fmt = "{}%", .0)] Percent(i32), #[display(fmt = "{}px", .0)] + #[debug(fmt = "{}px", .0)] Pixels(i32), } -impl fmt::Debug for NumWithUnit { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self) - } -} - impl FromStr for NumWithUnit { type Err = anyhow::Error; diff --git a/src/value/mod.rs b/src/value/mod.rs index d9219be..36ff12b 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -12,7 +12,8 @@ pub use primitive::*; /// The name of a variable #[repr(transparent)] -#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize, RefCast, AsRef, From, FromStr, Display)] +#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize, RefCast, AsRef, From, FromStr, Display, DebugCustom)] +#[debug(fmt = "VarName({})", .0)] pub struct VarName(pub String); impl std::borrow::Borrow for VarName { @@ -27,15 +28,10 @@ impl From<&str> for VarName { } } -impl fmt::Debug for VarName { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "VarName(\"{}\")", self.0) - } -} - /// The name of an attribute #[repr(transparent)] -#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize, RefCast, AsRef, From, FromStr, Display)] +#[derive(Clone, Hash, PartialEq, Eq, Serialize, Deserialize, RefCast, AsRef, From, FromStr, Display, DebugCustom)] +#[debug(fmt="AttrName({})", .0)] pub struct AttrName(pub String); impl std::borrow::Borrow for AttrName { @@ -49,9 +45,3 @@ impl From<&str> for AttrName { AttrName(s.to_owned()) } } - -impl fmt::Debug for AttrName { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "AttrName(\"{}\")", self.0) - } -}