simplify Unit::From<String>
This commit is contained in:
parent
01858ff543
commit
1b774a9b91
@ -155,45 +155,45 @@ impl Unit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&String> for Unit {
|
impl From<String> for Unit {
|
||||||
fn from(unit: &String) -> Self {
|
fn from(unit: String) -> Self {
|
||||||
match unit.to_ascii_lowercase().as_bytes() {
|
match unit.to_ascii_lowercase().as_str() {
|
||||||
b"px" => Unit::Px,
|
"px" => Unit::Px,
|
||||||
b"mm" => Unit::Mm,
|
"mm" => Unit::Mm,
|
||||||
b"in" => Unit::In,
|
"in" => Unit::In,
|
||||||
b"cm" => Unit::Cm,
|
"cm" => Unit::Cm,
|
||||||
b"q" => Unit::Q,
|
"q" => Unit::Q,
|
||||||
b"pt" => Unit::Pt,
|
"pt" => Unit::Pt,
|
||||||
b"pc" => Unit::Pc,
|
"pc" => Unit::Pc,
|
||||||
b"em" => Unit::Em,
|
"em" => Unit::Em,
|
||||||
b"rem" => Unit::Rem,
|
"rem" => Unit::Rem,
|
||||||
b"lh" => Unit::Lh,
|
"lh" => Unit::Lh,
|
||||||
b"%" => Unit::Percent,
|
"%" => Unit::Percent,
|
||||||
b"ex" => Unit::Ex,
|
"ex" => Unit::Ex,
|
||||||
b"ch" => Unit::Ch,
|
"ch" => Unit::Ch,
|
||||||
b"cap" => Unit::Cap,
|
"cap" => Unit::Cap,
|
||||||
b"ic" => Unit::Ic,
|
"ic" => Unit::Ic,
|
||||||
b"rlh" => Unit::Rlh,
|
"rlh" => Unit::Rlh,
|
||||||
b"vw" => Unit::Vw,
|
"vw" => Unit::Vw,
|
||||||
b"vh" => Unit::Vh,
|
"vh" => Unit::Vh,
|
||||||
b"vmin" => Unit::Vmin,
|
"vmin" => Unit::Vmin,
|
||||||
b"vmax" => Unit::Vmax,
|
"vmax" => Unit::Vmax,
|
||||||
b"vi" => Unit::Vi,
|
"vi" => Unit::Vi,
|
||||||
b"vb" => Unit::Vb,
|
"vb" => Unit::Vb,
|
||||||
b"deg" => Unit::Deg,
|
"deg" => Unit::Deg,
|
||||||
b"grad" => Unit::Grad,
|
"grad" => Unit::Grad,
|
||||||
b"rad" => Unit::Rad,
|
"rad" => Unit::Rad,
|
||||||
b"turn" => Unit::Turn,
|
"turn" => Unit::Turn,
|
||||||
b"s" => Unit::S,
|
"s" => Unit::S,
|
||||||
b"ms" => Unit::Ms,
|
"ms" => Unit::Ms,
|
||||||
b"hz" => Unit::Hz,
|
"hz" => Unit::Hz,
|
||||||
b"khz" => Unit::Khz,
|
"khz" => Unit::Khz,
|
||||||
b"dpi" => Unit::Dpi,
|
"dpi" => Unit::Dpi,
|
||||||
b"dpcm" => Unit::Dpcm,
|
"dpcm" => Unit::Dpcm,
|
||||||
b"dppx" => Unit::Dppx,
|
"dppx" => Unit::Dppx,
|
||||||
b"x" => Unit::X,
|
"x" => Unit::X,
|
||||||
b"fr" => Unit::Fr,
|
"fr" => Unit::Fr,
|
||||||
_ => Unit::Unknown(String::from(unit)),
|
_ => Unit::Unknown(unit),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ impl fmt::Display for Unit {
|
|||||||
Unit::X => write!(f, "x"),
|
Unit::X => write!(f, "x"),
|
||||||
Unit::Fr => write!(f, "fr"),
|
Unit::Fr => write!(f, "fr"),
|
||||||
Unit::Unknown(s) => write!(f, "{}", s),
|
Unit::Unknown(s) => write!(f, "{}", s),
|
||||||
Unit::None => write!(f, ""),
|
Unit::None => Ok(()),
|
||||||
Unit::Mul(u) => write!(
|
Unit::Mul(u) => write!(
|
||||||
f,
|
f,
|
||||||
"{}",
|
"{}",
|
||||||
|
@ -651,7 +651,7 @@ impl Value {
|
|||||||
Err(e) => return Some(Err(e)),
|
Err(e) => return Some(Err(e)),
|
||||||
};
|
};
|
||||||
span = span.merge(u.span);
|
span = span.merge(u.span);
|
||||||
Unit::from(&u.node)
|
Unit::from(u.node)
|
||||||
}
|
}
|
||||||
'%' => {
|
'%' => {
|
||||||
span = span.merge(toks.next().unwrap().pos());
|
span = span.merge(toks.next().unwrap().pos());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user