Fix minor style inconsistencies in serde::duration

This commit is contained in:
Jonas Platte 2020-04-15 23:00:14 +02:00
parent 9b5b906868
commit c35d38c95f
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 10 additions and 8 deletions

View File

@ -10,6 +10,7 @@ use serde::{
};
/// Serialize an Option<Duration>.
///
/// Will fail if integer is greater than the maximum integer that can be
/// unambiguously represented by an f64.
pub fn serialize<S>(opt_duration: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error>
@ -26,6 +27,7 @@ where
}
/// Deserializes an Option<Duration>.
///
/// Will fail if integer is greater than the maximum integer that can be
/// unambiguously represented by an f64.
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
@ -38,17 +40,14 @@ where
#[cfg(test)]
mod tests {
use std::time::Duration;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::time::Duration;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct DurationTest {
#[serde(
with = "crate::serde::duration::opt_ms",
default,
skip_serializing_if = "Option::is_none"
)]
#[serde(with = "super", default, skip_serializing_if = "Option::is_none")]
timeout: Option<Duration>,
}

View File

@ -10,6 +10,7 @@ use serde::{
};
/// Serializes a Duration to an integer representing seconds.
///
/// Will fail if integer is greater than the maximum integer that can be
/// unambiguously represented by an f64.
pub fn serialize<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
@ -23,6 +24,7 @@ where
}
/// Deserializes an integer representing seconds into a Duration.
///
/// Will fail if integer is greater than the maximum integer that can be
/// unambiguously represented by an f64.
pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
@ -34,13 +36,14 @@ where
#[cfg(test)]
mod tests {
use std::time::Duration;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::time::Duration;
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct DurationTest {
#[serde(with = "crate::serde::duration::secs")]
#[serde(with = "super")]
timeout: Duration,
}