1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # Serde Millis
//!
//! [Documentation](https://docs.rs/serde_millis) |
//! [Github](https://github.com/tailhook/serde-millis) |
//! [Crate](https://crates.io/crates/serde_millis)
//!
//! 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
//!
//! ```rust
//! #[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,
//! }
//!
//! #
//! # fn main() {}
//! ```
extern crate serde;
extern crate serde_json;
extern crate serde_derive;
pub use Milliseconds;
pub use ;