From 44f30b75d4bacaf62bba192da52d6fb697d2e78f Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 8 Jul 2024 12:18:41 +0200 Subject: [PATCH] remove allocation in deserialization --- src/wire/mod.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/wire/mod.rs b/src/wire/mod.rs index 32aa370..d1239d2 100644 --- a/src/wire/mod.rs +++ b/src/wire/mod.rs @@ -38,16 +38,15 @@ mod serde_rfc3339 { where D: Deserializer<'de>, { - Ok(String::deserialize(deserializer) - .and_then(|rfc_str| { - DateTime::parse_from_rfc3339(&rfc_str).map_err(|_| { - serde::de::Error::invalid_value( - Unexpected::Str(&rfc_str), - &"Invalid RFC3339 string", - ) - }) - })? - .into()) + let rfc_str = <&str as Deserialize>::deserialize(deserializer)?; + + match DateTime::parse_from_rfc3339(rfc_str) { + Ok(datetime) => Ok(datetime.into()), + Err(_) => Err(serde::de::Error::invalid_value( + Unexpected::Str(rfc_str), + &"Invalid RFC3339 string", + )), + } } }