From 4145d84a23611b9b6e476274d068ac8e674da88a Mon Sep 17 00:00:00 2001 From: Gnome! Date: Sat, 24 Jun 2023 17:17:59 +0100 Subject: [PATCH] Deserialize to `arrayvec::ArrayString` instead of `String` for `ImageHash` (#2467) This saves an allocation on creation of `ImageHash`. --- Cargo.toml | 1 + src/model/misc.rs | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bce3dcf40f8..84a47d8dfa0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ futures = { version = "0.3", default-features = false, features = ["std"] } dep_time = { version = "0.3.20", package = "time", features = ["formatting", "parsing", "serde-well-known"] } base64 = { version = "0.21" } secrecy = { version = "0.8.0", features = ["serde"] } +arrayvec = { version = "0.7.3", features = ["serde"] } # Optional dependencies fxhash = { version = "0.2.1", optional = true } simd-json = { version = "0.7", optional = true } diff --git a/src/model/misc.rs b/src/model/misc.rs index a16f42987ac..7f476196035 100644 --- a/src/model/misc.rs +++ b/src/model/misc.rs @@ -111,8 +111,7 @@ impl serde::Serialize for ImageHash { impl<'de> serde::Deserialize<'de> for ImageHash { fn deserialize>(deserializer: D) -> Result { - // TODO: Replace this with ArrayString<34>? - let helper = String::deserialize(deserializer)?; + let helper = arrayvec::ArrayString::<34>::deserialize(deserializer)?; Self::from_str(&helper).map_err(serde::de::Error::custom) } }