Croissant Runtime
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crsn/launcher/src/serde_duration_millis.rs

19 lines
452 B

use std::time::Duration;
use serde::{self, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(value: &Duration, se: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
se.serialize_u64(value.as_secs() * 1000 + value.subsec_millis() as u64)
}
pub fn deserialize<'de, D>(de: D) -> Result<Duration, D::Error>
where
D: Deserializer<'de>,
{
let s: u64 = u64::deserialize(de)?;
Ok(Duration::from_millis(s))
}