Module nt_time::serde_with::unix_time

source ·
Available on crate feature serde only.
Expand description

Use Unix time when serializing and deserializing a FileTime.

Use this module in combination with Serde’s with attribute.

§Examples

use nt_time::{
    serde::{Deserialize, Serialize},
    serde_with::unix_time,
    FileTime,
};

#[derive(Debug, Deserialize, PartialEq, Serialize)]
struct DateTime(#[serde(with = "unix_time")] FileTime);

let json = serde_json::to_string(&DateTime(FileTime::UNIX_EPOCH)).unwrap();
assert_eq!(json, "0");

assert_eq!(
    serde_json::from_str::<DateTime>(&json).unwrap(),
    DateTime(FileTime::UNIX_EPOCH)
);

Modules§

Functions§