duration-string
duration-string
is a string to duration and visa-versa lib.
Takes a string such as 100ms
, 2s
, 5m
and converts it into a Duration
Takes a duration and makes it into string.
The string format is [0-9]+(ms|[smhdwy])
Example
String to duration
use TryFrom;
use DurationString;
use Duration;
let d: Duration = try_from.unwrap.into;
assert_eq!;
duration to string
use TryFrom;
use *;
use Duration;
let d: String = from.into;
assert_eq!;
Serde support
You can enable serialize/unserialize support by adding the feature serde_support
- Add
serde_support
to the dependencyduration-string = { version = "0.0.1", features = ["serde_support"] }
- Add derive to struct
use ;
License: MIT