Use strum for SVGUnit

main
Elnu 1 year ago
parent 3b9c6d58de
commit 5254d3dc8f

33
Cargo.lock generated

@ -77,8 +77,16 @@ version = "0.1.0"
dependencies = [
"askama",
"derive_more",
"strum",
"strum_macros",
]
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "humansize"
version = "2.1.3"
@ -174,6 +182,12 @@ dependencies = [
"semver",
]
[[package]]
name = "rustversion"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]]
name = "semver"
version = "1.0.18"
@ -200,6 +214,25 @@ dependencies = [
"syn 2.0.28",
]
[[package]]
name = "strum"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
[[package]]
name = "strum_macros"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.28",
]
[[package]]
name = "syn"
version = "1.0.109"

@ -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,
}
@ -30,21 +37,3 @@ impl SVGUnit {
}
}
}
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",
}
)
}
}

@ -51,7 +51,7 @@ Updating `cargoHash`:
pname = "dyesub-tool";
version = "0.1.0";
buildAndTestSubdir = "dyesub-tool";
cargoHash = "sha256-owoTOMY/u7K3Y96FIHXMJeqILAOFR2wSYozzsT+0p64=";
cargoHash = "sha256-WUA3ysG7SlylV1y5nkPxLRGVa4NktFjpawE97d3b36I=";
meta = meta // {
description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift keycaps.";
};

Loading…
Cancel
Save