From dfe53494d473a341ce49e102a7d1d4ff3ea06c97 Mon Sep 17 00:00:00 2001 From: Awpteamoose Date: Wed, 17 Jul 2024 15:10:28 +0100 Subject: [PATCH] fmt --- src/time_delta.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/time_delta.rs b/src/time_delta.rs index 9599c001f..ee158dcf1 100644 --- a/src/time_delta.rs +++ b/src/time_delta.rs @@ -64,25 +64,24 @@ pub struct TimeDelta { #[cfg(feature = "serde")] impl serde::Serialize for TimeDelta { - fn serialize(&self, serializer: S) -> Result { - <(i64, i32) as serde::Serialize>::serialize(&(self.secs, self.nanos), serializer) - } + fn serialize(&self, serializer: S) -> Result { + <(i64, i32) as serde::Serialize>::serialize(&(self.secs, self.nanos), serializer) + } } #[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for TimeDelta { - fn deserialize>(deserializer: D) -> Result { - let (secs, nanos) = <(i64, i32) as serde::Deserialize>::deserialize(deserializer)?; - if secs < MIN.secs - || secs > MAX.secs + fn deserialize>(deserializer: D) -> Result { + let (secs, nanos) = <(i64, i32) as serde::Deserialize>::deserialize(deserializer)?; + if !(MIN.secs..=MAX.secs).contains(&secs) || nanos >= 1_000_000_000 || (secs == MAX.secs && nanos > MAX.nanos) || (secs == MIN.secs && nanos < MIN.nanos) { return Err(serde::de::Error::custom("TimeDelta out of bounds")); } - Ok(TimeDelta { secs, nanos }) - } + Ok(TimeDelta { secs, nanos }) + } } /// The minimum possible `TimeDelta`: `-i64::MAX` milliseconds. @@ -1333,6 +1332,9 @@ mod tests { #[cfg(feature = "serde")] fn test_serde() { let duration = TimeDelta::new(123, 456).unwrap(); - assert_eq!(serde_json::from_value::(serde_json::to_value(&duration).unwrap()).unwrap(), duration); + assert_eq!( + serde_json::from_value::(serde_json::to_value(duration).unwrap()).unwrap(), + duration + ); } }