generated from ElnuDev/rust-project
Use strum for SVGUnit
This commit is contained in:
parent
3b9c6d58de
commit
5254d3dc8f
4 changed files with 45 additions and 21 deletions
|
@ -6,3 +6,5 @@ edition = "2021"
|
|||
[dependencies]
|
||||
askama = "0.12.0"
|
||||
derive_more = "0.99.17"
|
||||
strum = "0.25.0"
|
||||
strum_macros = "0.25.2"
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
use std::fmt::{self, Display};
|
||||
use strum_macros::{Display, EnumString, IntoStaticStr};
|
||||
|
||||
/// https://oreillymedia.github.io/Using_SVG/guide/units.html
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
#[derive(Display, EnumString, IntoStaticStr)]
|
||||
pub enum SVGUnit {
|
||||
/// Pixel units, directly equivalent to SVG user units.
|
||||
#[strum(serialize = "px")]
|
||||
Pixel,
|
||||
/// Inches.
|
||||
#[strum(serialize = "in")]
|
||||
Inch,
|
||||
/// Centimeters.
|
||||
#[strum(serialize = "cm")]
|
||||
Centimeter,
|
||||
/// Millimeters.
|
||||
#[strum(serialize = "mm")]
|
||||
Millimeter,
|
||||
/// Points.
|
||||
#[strum(serialize = "pt")]
|
||||
Point,
|
||||
// Picas.
|
||||
#[strum(serialize = "pc")]
|
||||
Pica,
|
||||
}
|
||||
|
||||
|
@ -29,22 +36,4 @@ impl SVGUnit {
|
|||
Pica => 16.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SVGUnit {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use SVGUnit::*;
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match &self {
|
||||
Pixel => "px",
|
||||
Inch => "in",
|
||||
Centimeter => "cm",
|
||||
Millimeter => "mm",
|
||||
Point => "pt",
|
||||
Pica => "pc",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue