From f7bffc992d6753ff5923f2661c93de00a773e461 Mon Sep 17 00:00:00 2001 From: Max Verevkin <34583604+MaxVerevkin@users.noreply.github.com> Date: Fri, 16 Feb 2024 07:17:39 +0200 Subject: [PATCH] drop serde_with dependency (#2001) --- Cargo.lock | 146 +++----------------------------------------- Cargo.toml | 6 +- src/blocks/sound.rs | 29 +++------ src/wrappers.rs | 14 +++++ 4 files changed, 35 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f055a071cc..0f18a564c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,7 +476,6 @@ dependencies = [ "iana-time-zone", "num-traits", "pure-rust-locales", - "serde", "windows-targets 0.48.5", ] @@ -650,18 +649,8 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" dependencies = [ - "darling_core 0.10.2", - "darling_macro 0.10.2", -] - -[[package]] -name = "darling" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" -dependencies = [ - "darling_core 0.20.3", - "darling_macro 0.20.3", + "darling_core", + "darling_macro", ] [[package]] @@ -678,42 +667,17 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "darling_core" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim 0.10.0", - "syn 2.0.48", -] - [[package]] name = "darling_macro" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ - "darling_core 0.10.2", + "darling_core", "quote", "syn 1.0.109", ] -[[package]] -name = "darling_macro" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" -dependencies = [ - "darling_core 0.20.3", - "quote", - "syn 2.0.48", -] - [[package]] name = "data-encoding" version = "2.5.0" @@ -730,16 +694,6 @@ dependencies = [ "futures-util", ] -[[package]] -name = "deranged" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" -dependencies = [ - "powerfmt", - "serde", -] - [[package]] name = "derivative" version = "2.2.0" @@ -989,7 +943,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e08079fa3c89edec9160ceaa9e7172785468c26c053d12924cce0d5a55c241a" dependencies = [ - "darling 0.10.2", + "darling", "proc-macro2", "quote", "syn 1.0.109", @@ -1161,19 +1115,13 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 2.1.0", + "indexmap", "slab", "tokio", "tokio-util", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.3" @@ -1295,6 +1243,7 @@ dependencies = [ "icu_calendar", "icu_datetime", "icu_locid", + "indexmap", "inotify 0.10.2", "itertools", "libc", @@ -1313,7 +1262,6 @@ dependencies = [ "sensors", "serde", "serde_json", - "serde_with", "shellexpand", "signal-hook", "signal-hook-tokio", @@ -1544,17 +1492,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", - "serde", -] - [[package]] name = "indexmap" version = "2.1.0" @@ -1562,7 +1499,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown", "serde", ] @@ -2272,12 +2209,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2624,35 +2555,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" -dependencies = [ - "base64 0.21.7", - "chrono", - "hex", - "indexmap 1.9.3", - "indexmap 2.1.0", - "serde", - "serde_json", - "serde_with_macros", - "time", -] - -[[package]] -name = "serde_with_macros" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" -dependencies = [ - "darling 0.20.3", - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "sha1" version = "0.10.6" @@ -2918,35 +2820,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "time" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e" -dependencies = [ - "deranged", - "itoa", - "powerfmt", - "serde", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" - -[[package]] -name = "time-macros" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f" -dependencies = [ - "time-core", -] - [[package]] name = "tinystr" version = "0.7.5" @@ -3032,6 +2905,7 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" dependencies = [ + "indexmap", "serde", "serde_spanned", "toml_datetime", @@ -3053,7 +2927,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.1.0", + "indexmap", "toml_datetime", "winnow", ] @@ -3064,7 +2938,7 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ - "indexmap 2.1.0", + "indexmap", "serde", "serde_spanned", "toml_datetime", diff --git a/Cargo.toml b/Cargo.toml index 7e863bec5a..ea3be47251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,9 +42,10 @@ env_logger = "0.11" futures = { version = "0.3", default-features = false } glob = { version = "0.3.1", optional = true } hyper = "0.14" -icu_datetime = { version = "1.3.0", optional = true } icu_calendar = { version = "1.3.0", optional = true } +icu_datetime = { version = "1.3.0", optional = true } icu_locid = { version = "1.3.0", optional = true } +indexmap = { version = "2.0", features = ["serde"] } inotify = "0.10" itertools = "0.12" libc = "0.2" @@ -63,14 +64,13 @@ reqwest = { version = "0.11", features = ["json"] } sensors = "0.2.2" serde = { version = "1.0", features = ["derive", "rc"] } serde_json = "1.0" -serde_with = "3.0" shellexpand = "3.0" signal-hook = "0.3" signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] } smart-default = "0.7" swayipc-async = "2.0" thiserror = "1.0" -toml = "0.8" +toml = { version = "0.8", features = ["preserve_order"] } unicode-segmentation = "1.10.1" wayrs-client = { version = "1.0", features = ["tokio"] } wayrs-protocols = { version = "0.13", features = ["wlr-foreign-toplevel-management-unstable-v1"] } diff --git a/src/blocks/sound.rs b/src/blocks/sound.rs index f78128d06d..9324c43cdb 100644 --- a/src/blocks/sound.rs +++ b/src/blocks/sound.rs @@ -95,19 +95,10 @@ mod alsa; mod pulseaudio; use super::prelude::*; +use crate::wrappers::SerdeRegex; +use indexmap::IndexMap; use regex::Regex; -use serde_with::{serde_as, serde_conv, Map}; -// A conversion adapter that is used to convert Regex to String and vice versa -// when serializing or deserializing using serde. -serde_conv!( - RegexAsString, - Regex, - |regex: &Regex| regex.as_str().to_string(), - |value: String| Regex::new(&value) -); - -#[serde_as] #[derive(Deserialize, Debug, SmartDefault)] #[serde(deny_unknown_fields, default)] pub struct Config { @@ -121,17 +112,15 @@ pub struct Config { pub format: FormatConfig, pub headphones_indicator: bool, pub show_volume_when_muted: bool, - #[serde_as(as = "Option>")] - pub mappings: Option>, + pub mappings: Option>, #[default(true)] pub mappings_use_regex: bool, pub max_vol: Option, - #[serde_as(as = "Map")] - pub active_port_mappings: Vec<(Regex, String)>, + pub active_port_mappings: IndexMap, } enum Mappings<'a> { - Exact(&'a [(String, String)]), + Exact(&'a IndexMap), Regex(Vec<(Regex, &'a str)>), } @@ -249,9 +238,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> { } } Some(Mappings::Exact(m)) => { - if let Some((_, mapped)) = - m.iter().find(|&(exact, _)| output_name == exact.as_str()) - { + if let Some(mapped) = m.get(&output_name) { output_name = mapped.clone(); } } @@ -261,9 +248,9 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> { if let Some((regex, mapped)) = config .active_port_mappings .iter() - .find(|(regex, _)| regex.is_match(ap)) + .find(|(regex, _)| regex.0.is_match(ap)) { - let mapped = regex.replace(ap, mapped); + let mapped = regex.0.replace(ap, mapped); if mapped.is_empty() { active_port = None; } else { diff --git a/src/wrappers.rs b/src/wrappers.rs index 1c055166d5..12e2072cb6 100644 --- a/src/wrappers.rs +++ b/src/wrappers.rs @@ -195,6 +195,20 @@ where #[derive(Debug, Clone)] pub struct SerdeRegex(pub regex::Regex); +impl PartialEq for SerdeRegex { + fn eq(&self, other: &Self) -> bool { + self.0.as_str() == other.0.as_str() + } +} + +impl Eq for SerdeRegex {} + +impl std::hash::Hash for SerdeRegex { + fn hash(&self, state: &mut H) { + self.0.as_str().hash(state); + } +} + impl<'de> Deserialize<'de> for SerdeRegex { fn deserialize(deserializer: D) -> Result where