Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Awpteamoose committed Jul 17, 2024
1 parent f3f66ee commit 315649e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/time_delta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ pub struct TimeDelta {

#[cfg(feature = "serde")]
impl serde::Serialize for TimeDelta {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
<(i64, i32) as serde::Serialize>::serialize(&(self.secs, self.nanos), serializer)
}
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
<(i64, i32) as serde::Serialize>::serialize(&(self.secs, self.nanos), serializer)
}
}

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for TimeDelta {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let (secs, nanos) = <(i64, i32) as serde::Deserialize>::deserialize(deserializer)?;
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let (secs, nanos) = <(i64, i32) as serde::Deserialize>::deserialize(deserializer)?;
if secs < MIN.secs
|| secs > MAX.secs
|| nanos >= 1_000_000_000
Expand All @@ -81,8 +81,8 @@ impl<'de> serde::Deserialize<'de> for TimeDelta {
{
return Err(serde::de::Error::custom("TimeDelta out of bounds"));

Check warning on line 82 in src/time_delta.rs

View check run for this annotation

Codecov / codecov/patch

src/time_delta.rs#L82

Added line #L82 was not covered by tests
}
Ok(TimeDelta { secs, nanos })
}
Ok(TimeDelta { secs, nanos })
}
}

/// The minimum possible `TimeDelta`: `-i64::MAX` milliseconds.
Expand Down Expand Up @@ -1333,6 +1333,9 @@ mod tests {
#[cfg(feature = "serde")]
fn test_serde() {
let duration = TimeDelta::new(123, 456).unwrap();
assert_eq!(serde_json::from_value::<TimeDelta>(serde_json::to_value(&duration).unwrap()).unwrap(), duration);
assert_eq!(
serde_json::from_value::<TimeDelta>(serde_json::to_value(&duration).unwrap()).unwrap(),
duration
);
}
}

0 comments on commit 315649e

Please sign in to comment.