All checks were successful
continuous-integration/drone/push Build is passing
22 lines
556 B
Rust
22 lines
556 B
Rust
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
|
|
pub mod duration {
|
|
use super::*;
|
|
use std::time::Duration;
|
|
|
|
pub fn serialize<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
duration.as_secs_f64().serialize(serializer)
|
|
}
|
|
|
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let secs: f64 = Deserialize::deserialize(deserializer)?;
|
|
Ok(Duration::from_secs_f64(secs))
|
|
}
|
|
}
|