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
//! A Serde deserializer for duration and byte-size using the crate [`humanize-rs`].
//!
//! # Example
//! ```
//! extern crate serde;
//! #[macro_use] extern crate serde_derive;
//! extern crate serde_json;
//! extern crate serde_humanize_rs;
//!
//! use std::time::Duration;
//!
//! #[derive(Deserialize)]
//! struct Config {
//! #[serde(with = "serde_humanize_rs")]
//! size: usize,
//!
//! #[serde(with = "serde_humanize_rs")]
//! interval: Duration,
//! }
//!
//! let json = r#"{"size": "1 M", "interval": "1h30m"}"#;
//! let cfg = serde_json::from_str::<Config>(json).unwrap();
//! assert_eq!(cfg.size, 1_000_000);
//! assert_eq!(cfg.interval, Duration::from_secs(5400));
//! ```
//!
//! [`humanize-rs`]: https://github.com/dtynn/humanize-rs
extern crate humanize_rs;
extern crate serde;
extern crate serde_derive;
extern crate serde_json;
pub use deserialize;