Function chrono::serde::ts_seconds::deserialize
source · pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>where
D: Deserializer<'de>,
Expand description
Deserialize a DateTime
from a seconds timestamp
Intended for use with serde
s deserialize_with
attribute.
§Example:
use chrono::serde::ts_seconds::deserialize as from_ts;
#[derive(Debug, PartialEq, Deserialize)]
struct S {
#[serde(deserialize_with = "from_ts")]
time: DateTime<Utc>,
}
let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?;
assert_eq!(my_s, S { time: Utc.timestamp_opt(1431684000, 0).unwrap() });