duration-string
duration-string is a library to convert from String to Duration and vice-versa.
Uses zero dependencies unless serde feature is enabled.
Takes a String such as 100ms, 2s, 5m 30s, 1h10m and converts it into a Duration.
Takes a Duration and converts it into String.
The String format is a multiply of [0-9]+(ns|us|ms|[smhdwy])
Example
String to Duration:
use TryFrom;
use DurationString;
use Duration;
let d: Duration = try_from.unwrap.into;
assert_eq!;
// Alternatively
let d: Duration = "100ms"..unwrap.into;
assert_eq!;
Duration to String:
use TryFrom;
use *;
use Duration;
let d: String = from.into;
assert_eq!;
Serde support
You can enable serialization/deserialization support by adding the feature serde
-
Add
serdefeature= { = "0.5.3", = ["serde"] } -
Add derive to struct
use DurationString; use ;
License
This project is licensed under the MIT License.
See LICENSE file for details.