sprinklers_rs/src/serde.rs
Alex Mikhalev af0998a719
All checks were successful
continuous-integration/drone/push Build is passing
Implement running sections through MQTT
2020-09-29 23:25:28 -06:00

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))
}
}