diff --git a/Cargo.lock b/Cargo.lock index 7cd75c2..518257e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -518,7 +518,6 @@ dependencies = [ "clap", "clap_derive", "dyesub", - "svg-units", ] [[package]] @@ -585,20 +584,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "err-derive" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34a887c8df3ed90498c1c437ce21f211c8e27672921a8ffa293cb8d6d4caa9e" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", - "synstructure", -] - [[package]] name = "errno" version = "0.3.2" @@ -1978,7 +1963,7 @@ dependencies = [ name = "svg-units" version = "0.1.0" dependencies = [ - "err-derive", + "derive_more", "lazy_static", "regex", "strum", @@ -2019,18 +2004,6 @@ dependencies = [ "syn 2.0.28", ] -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", - "unicode-xid", -] - [[package]] name = "thiserror" version = "1.0.47" diff --git a/Cargo.toml b/Cargo.toml index 083bd5f..35797e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] members = ["dyesub-tool", "dyesub-cli", "dyesub", "svg-units"] -resolver = "2" +resolver = "2" \ No newline at end of file diff --git a/dyesub-cli/Cargo.toml b/dyesub-cli/Cargo.toml index 8c88a67..c32d273 100644 --- a/dyesub-cli/Cargo.toml +++ b/dyesub-cli/Cargo.toml @@ -9,4 +9,3 @@ edition = "2021" clap = "4.3.23" clap_derive = "4.3.12" dyesub = { path = "../dyesub" } -svg-units = { path = "../svg-units" } \ No newline at end of file diff --git a/dyesub-cli/src/main.rs b/dyesub-cli/src/main.rs index 2128824..b34d06b 100644 --- a/dyesub-cli/src/main.rs +++ b/dyesub-cli/src/main.rs @@ -1,8 +1,10 @@ +#![feature(path_file_prefix)] + use std::path::PathBuf; use clap::Parser; use clap_derive::Parser; -use svg_units::SVGMeasure; +use dyesub::Result; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] @@ -12,15 +14,9 @@ struct Args { /// Output SVG path #[arg(short, long)] output: Option, - /// Page width - #[arg(long, default_value="11in")] - width: SVGMeasure, - /// Page height - #[arg(long, default_value="8.5in")] - height: SVGMeasure, } -fn main() -> dyesub::Result<()> { +fn main() -> Result<()> { let args = Args::parse(); let output = args.output.unwrap_or_else(|| { let mut path = args.input.clone(); diff --git a/flake.nix b/flake.nix index 3f929a3..dd97bc6 100644 --- a/flake.nix +++ b/flake.nix @@ -32,14 +32,18 @@ Updating `cargoHash`: }; # nightly is required for function signal syntax in leptos # https://leptos-rs.github.io/leptos/02_getting_started.html - rust = pkgs.rust-bin.nightly.latest; - # binary for output binary derivations - # (doesn't include dev tooling e.g. clippy) - rust-bin = rust.minimal; + rust-bin = pkgs.rust-bin.nightly.latest.minimal; + rust-binWasm = rust-bin.override { + targets = [ "wasm32-unknown-unknown" ]; + }; rustPlatform = pkgs.makeRustPlatform { cargo = rust-bin; rustc = rust-bin; }; + rustPlatformWasm = pkgs.makeRustPlatform { + cargo = rust-binWasm; + rustc = rust-binWasm; + }; rustSettings = with pkgs; { src = ./.; cargoHash = nixpkgs.lib.fakeHash; @@ -52,9 +56,8 @@ Updating `cargoHash`: in { devShells.${system}.default = with pkgs; mkShell { packages = [ - (rust.default.override { + (rust-binWasm.override { extensions = [ "rust-src" ]; - targets = [ "wasm32-unknown-unknown" ]; }) bacon ]; @@ -66,13 +69,13 @@ Updating `cargoHash`: pname = "dyesub-cli"; version = "0.1.0"; buildAndTestSubdir = "dyesub-cli"; - cargoHash = "sha256-6nbUjVjroFp2KZEk0wDisCUw2e9GtVxFgsGZm8xEe2A="; + cargoHash = "sha256-S4GvLg/B/FxjNyrQyBg25OMTgJVVBwPO+Dy/EFM4WoQ="; meta = meta // { description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift 拇指シフト keycaps."; }; }); dyesub-tool = let - rustToolchain = rust.minimal.override { + rustToolchain = pkgs.rust-bin.nightly.latest.minimal.override { targets = [ "wasm32-unknown-unknown" ]; }; craneLib = ((crane.mkLib pkgs).overrideToolchain rustToolchain).overrideScope' (final: prev: { diff --git a/svg-units/Cargo.toml b/svg-units/Cargo.toml index 7891f26..4189723 100644 --- a/svg-units/Cargo.toml +++ b/svg-units/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -err-derive = "0.3.1" +derive_more = "0.99.17" lazy_static = "1.4.0" regex = "1.9.3" strum = "0.25.0" diff --git a/svg-units/src/lib.rs b/svg-units/src/lib.rs index a911cb2..d2d5fb1 100644 --- a/svg-units/src/lib.rs +++ b/svg-units/src/lib.rs @@ -2,7 +2,7 @@ mod unit; pub use unit::SVGUnit; mod measure; -pub use measure::{SVGMeasure, SVGMeasureParseError}; +pub use measure::SVGMeasure; #[cfg(test)] mod tests; diff --git a/svg-units/src/measure.rs b/svg-units/src/measure.rs index 902af66..e9c3afa 100644 --- a/svg-units/src/measure.rs +++ b/svg-units/src/measure.rs @@ -1,5 +1,5 @@ use super::SVGUnit; -use err_derive::Error; +use derive_more::From; use lazy_static::lazy_static; use regex::Regex; use std::cmp::Ordering; @@ -35,18 +35,15 @@ impl SVGMeasure { } } -#[derive(Debug, Error)] -pub enum SVGMeasureParseError { - #[error(display = "Failed to parse measure number")] - ParseMeasure(#[source] ParseFloatError), - #[error(display = "Failed to parse measure unit")] - ParseUnit(#[source] ParseError), - #[error(display = "Invalid measure format")] +#[derive(From, Debug)] +pub enum SVGUnitParseError { + ParseMeasure(ParseFloatError), + ParseUnit(ParseError), Invalid, } impl FromStr for SVGMeasure { - type Err = SVGMeasureParseError; + type Err = SVGUnitParseError; fn from_str(s: &str) -> Result { if s == "0" { return Ok(SVGMeasure::new(0.0, SVGUnit::Pixel)); @@ -59,19 +56,11 @@ impl FromStr for SVGMeasure { let unit = captures[2].parse::()?; Ok(SVGMeasure::new(measure, unit)) } else { - Err(SVGMeasureParseError::Invalid) + Err(SVGUnitParseError::Invalid) } } } -impl<'s> TryFrom<&'s str> for SVGMeasure { - type Error = SVGMeasureParseError; - - fn try_from(value: &'s str) -> Result { - Self::from_str(value) - } -} - const EQ_TOLERANCE: f64 = 0.00001; impl PartialEq for SVGMeasure {