cargo fmt

This commit is contained in:
Jonas Platte 2020-04-24 12:17:59 +02:00
parent 41288b7c73
commit 32d95057a6
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 32 additions and 8 deletions

View File

@ -13,7 +13,10 @@ use serde::{
/// ///
/// 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>
where where
S: Serializer, S: Serializer,
{ {
@ -30,7 +33,9 @@ where
/// ///
/// 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>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
@ -47,7 +52,11 @@ mod tests {
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct DurationTest { struct DurationTest {
#[serde(with = "super", default, skip_serializing_if = "Option::is_none")] #[serde(
with = "super",
default,
skip_serializing_if = "Option::is_none"
)]
timeout: Option<Duration>, timeout: Option<Duration>,
} }

View File

@ -13,7 +13,10 @@ use serde::{
/// ///
/// 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>
where where
S: Serializer, S: Serializer,
{ {
@ -64,6 +67,9 @@ mod tests {
let test = DurationTest { let test = DurationTest {
timeout: Duration::from_millis(7000), timeout: Duration::from_millis(7000),
}; };
assert_eq!(serde_json::to_value(test).unwrap(), json!({ "timeout": 7 }),); assert_eq!(
serde_json::to_value(test).unwrap(),
json!({ "timeout": 7 }),
);
} }
} }

View File

@ -14,7 +14,10 @@ use serde::{
/// ///
/// Will fail if integer is greater than the maximum integer that can be unambiguously represented /// Will fail if integer is greater than the maximum integer that can be unambiguously represented
/// by an f64. /// by an f64.
pub fn serialize<S>(opt_time: &Option<SystemTime>, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(
opt_time: &Option<SystemTime>,
serializer: S,
) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
@ -28,7 +31,9 @@ where
/// ///
/// Will fail if integer is greater than the maximum integer that can be unambiguously represented /// Will fail if integer is greater than the maximum integer that can be unambiguously represented
/// by an f64. /// by an f64.
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<SystemTime>, D::Error> pub fn deserialize<'de, D>(
deserializer: D,
) -> Result<Option<SystemTime>, D::Error>
where where
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
@ -45,7 +50,11 @@ mod tests {
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct SystemTimeTest { struct SystemTimeTest {
#[serde(with = "super", default, skip_serializing_if = "Option::is_none")] #[serde(
with = "super",
default,
skip_serializing_if = "Option::is_none"
)]
timestamp: Option<SystemTime>, timestamp: Option<SystemTime>,
} }