Crate serde_millis [] [src]

Serde Millis

Documentation | Github | Crate

A serde wrapper, that can be used to serialize timestamps and durations as milliseconds. It's often useful together with serde_json to communicate with Javascript.

Example

#[macro_use]
extern crate serde_derive;

extern crate serde;
extern crate serde_millis;

use std::time::{Duration, SystemTime, Instant};

#[derive(Serialize, Deserialize)]
struct Timestamps {
    #[serde(with = "serde_millis")]
    time: SystemTime,

    #[serde(with = "serde_millis")]
    latency: Duration,

    // Instant is serialized relative to the current time, or in
    // other words by formula (but works for future instants too):
    //
    //   ts = SystemTime::now() - (Instant::now() - target_instant)
    //
    #[serde(with = "serde_millis")]
    timestamp: Instant,
}

Traits

Milliseconds

A value convertible to milliseconds since unix epoch

Functions

deserialize

Deserialize function, see crate docs to see how to use it

serialize

Deserialize function, see crate docs to see how to use it