Fix minor style inconsistencies in serde::duration
This commit is contained in:
parent
9b5b906868
commit
c35d38c95f
@ -10,6 +10,7 @@ use serde::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Serialize an Option<Duration>.
|
/// Serialize an Option<Duration>.
|
||||||
|
///
|
||||||
/// Will fail if integer is greater than the maximum integer that can be
|
/// Will fail if integer is greater than the maximum integer that can be
|
||||||
/// unambiguously represented by an f64.
|
/// unambiguously represented by an f64.
|
||||||
pub fn serialize<S>(opt_duration: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize<S>(opt_duration: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
@ -26,6 +27,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deserializes an Option<Duration>.
|
/// Deserializes an Option<Duration>.
|
||||||
|
///
|
||||||
/// Will fail if integer is greater than the maximum integer that can be
|
/// Will fail if integer is greater than the maximum integer that can be
|
||||||
/// unambiguously represented by an f64.
|
/// unambiguously represented by an f64.
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Duration>, D::Error>
|
||||||
@ -38,17 +40,14 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
struct DurationTest {
|
struct DurationTest {
|
||||||
#[serde(
|
#[serde(with = "super", default, skip_serializing_if = "Option::is_none")]
|
||||||
with = "crate::serde::duration::opt_ms",
|
|
||||||
default,
|
|
||||||
skip_serializing_if = "Option::is_none"
|
|
||||||
)]
|
|
||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ use serde::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Serializes a Duration to an integer representing seconds.
|
/// Serializes a Duration to an integer representing seconds.
|
||||||
|
///
|
||||||
/// Will fail if integer is greater than the maximum integer that can be
|
/// Will fail if integer is greater than the maximum integer that can be
|
||||||
/// unambiguously represented by an f64.
|
/// unambiguously represented by an f64.
|
||||||
pub fn serialize<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
|
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.
|
/// Deserializes an integer representing seconds into a Duration.
|
||||||
|
///
|
||||||
/// Will fail if integer is greater than the maximum integer that can be
|
/// Will fail if integer is greater than the maximum integer that can be
|
||||||
/// unambiguously represented by an f64.
|
/// unambiguously represented by an f64.
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
||||||
@ -34,13 +36,14 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
struct DurationTest {
|
struct DurationTest {
|
||||||
#[serde(with = "crate::serde::duration::secs")]
|
#[serde(with = "super")]
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user