🧑‍💻 Replace "impl ToString" with "impl Display"

This commit is contained in:
Manuel Cillero 2024-07-27 20:12:07 +02:00
parent c1e641723b
commit 2c6e9238ab
6 changed files with 230 additions and 225 deletions

View file

@ -1,4 +1,6 @@
use crate::{concat_string, AutoDefault};
use crate::AutoDefault;
use std::fmt;
// About pixels: Pixels (px) are relative to the viewing device. For low-dpi devices, 1px is one
// device pixel (dot) of the display. For printers and high resolution screens 1px implies multiple
@ -31,24 +33,24 @@ pub enum Value {
}
#[rustfmt::skip]
impl ToString for Value {
fn to_string(&self) -> String {
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Value::None => "".to_owned(),
Value::Auto => "auto".to_owned(),
Value::None => write!(f, ""),
Value::Auto => write!(f, "auto"),
// Absolute value.
Value::Cm(av) => concat_string!(av.to_string(), "cm"),
Value::In(av) => concat_string!(av.to_string(), "in"),
Value::Mm(av) => concat_string!(av.to_string(), "mm"),
Value::Pc(av) => concat_string!(av.to_string(), "pc"),
Value::Pt(av) => concat_string!(av.to_string(), "pt"),
Value::Px(av) => concat_string!(av.to_string(), "px"),
Value::Cm(av) => write!(f, "{av}cm"),
Value::In(av) => write!(f, "{av}in"),
Value::Mm(av) => write!(f, "{av}mm"),
Value::Pc(av) => write!(f, "{av}pc"),
Value::Pt(av) => write!(f, "{av}pt"),
Value::Px(av) => write!(f, "{av}px"),
// Relative value.
Value::RelEm(rv) => concat_string!(rv.to_string(), "em"),
Value::RelPct(rv) => concat_string!(rv.to_string(), "%"),
Value::RelRem(rv) => concat_string!(rv.to_string(), "rem"),
Value::RelVh(rv) => concat_string!(rv.to_string(), "vh"),
Value::RelVw(rv) => concat_string!(rv.to_string(), "vw"),
Value::RelEm(rv) => write!(f, "{rv}em"),
Value::RelPct(rv) => write!(f, "{rv}%"),
Value::RelRem(rv) => write!(f, "{rv}rem"),
Value::RelVh(rv) => write!(f, "{rv}vh"),
Value::RelVw(rv) => write!(f, "{rv}vw"),
}
}
}