From 5254d3dc8f234c9609fa98f75308a3f449c04456 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Mon, 14 Aug 2023 12:29:52 -0700 Subject: [PATCH] Use strum for SVGUnit --- Cargo.lock | 33 +++++++++++++++++++++++++++++++++ dyesub-tool/Cargo.toml | 2 ++ dyesub-tool/src/svg/unit.rs | 29 +++++++++-------------------- flake.nix | 2 +- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 323df3f..8ae7457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/dyesub-tool/Cargo.toml b/dyesub-tool/Cargo.toml index 1ff22f0..a67246a 100644 --- a/dyesub-tool/Cargo.toml +++ b/dyesub-tool/Cargo.toml @@ -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" diff --git a/dyesub-tool/src/svg/unit.rs b/dyesub-tool/src/svg/unit.rs index 9c67baf..762a535 100644 --- a/dyesub-tool/src/svg/unit.rs +++ b/dyesub-tool/src/svg/unit.rs @@ -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", - } - ) - } -} +} \ No newline at end of file diff --git a/flake.nix b/flake.nix index 98edfdf..7042f94 100644 --- a/flake.nix +++ b/flake.nix @@ -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."; };