Skip to content

Commit

Permalink
Deserialize to arrayvec::ArrayString instead of String for `Image…
Browse files Browse the repository at this point in the history
…Hash` (#2467)

This saves an allocation on creation of `ImageHash`.
  • Loading branch information
GnomedDev committed Jun 24, 2023
1 parent 755f07c commit 4145d84
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions src/model/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ impl serde::Serialize for ImageHash {

impl<'de> serde::Deserialize<'de> for ImageHash {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
// 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)
}
}
Expand Down

0 comments on commit 4145d84

Please sign in to comment.