https://github.com/tailhook/serde-millis
A serde wrapper that stores integer millisecond value for timestamps and durations (used similarly to serde_bytes)
https://github.com/tailhook/serde-millis
milliseconds rust serde serialization timestamps
Last synced: 11 months ago
JSON representation
A serde wrapper that stores integer millisecond value for timestamps and durations (used similarly to serde_bytes)
- Host: GitHub
- URL: https://github.com/tailhook/serde-millis
- Owner: tailhook
- License: apache-2.0
- Created: 2017-11-28T14:53:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T15:59:17.000Z (over 5 years ago)
- Last Synced: 2024-05-09T14:46:58.779Z (almost 2 years ago)
- Topics: milliseconds, rust, serde, serialization, timestamps
- Language: Rust
- Size: 18.6 KB
- Stars: 7
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
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,
}
```
License
=======
Licensed under either of
* Apache License, Version 2.0,
(./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
------------
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.