Available on crate features
serde
and serde-human-readable
only.Expand description
Use the well-known RFC 3339 format when serializing and deserializing an
Option<FileTime>
.
Use this module in combination with Serde’s with
attribute.
§Examples
use nt_time::{
serde::{Deserialize, Serialize},
serde_with::rfc_3339,
FileTime,
};
#[derive(Deserialize, Serialize)]
struct Time {
#[serde(with = "rfc_3339::option")]
time: Option<FileTime>,
}
let ft = Time {
time: Some(FileTime::UNIX_EPOCH),
};
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":"1970-01-01T00:00:00Z"}"#);
let ft: Time = serde_json::from_str(&json).unwrap();
assert_eq!(ft.time, Some(FileTime::UNIX_EPOCH));
let ft = Time { time: None };
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":null}"#);
let ft: Time = serde_json::from_str(&json).unwrap();
assert_eq!(ft.time, None);
Functions§
- Deserializes an
Option<FileTime>
from the given Serde deserializer. - Serializes an
Option<FileTime>
into the given Serde serializer.