Function chrono::serde::ts_microseconds_option::deserialize
source · pub fn deserialize<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>where
D: Deserializer<'de>,
Expand description
Deserialize a DateTime
from a microsecond timestamp or none
Intended for use with serde
s deserialize_with
attribute.
Example:
use chrono::serde::ts_microseconds_option::deserialize as from_micro_tsopt;
#[derive(Debug, PartialEq, Deserialize)]
struct S {
#[serde(deserialize_with = "from_micro_tsopt")]
time: Option<DateTime<Utc>>
}
let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?;
assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355000).single() });