Function jackdauer::duration [−][src]
pub fn duration(input: &str) -> Result<Duration, Error>
Expand description
Parses a std::time::Duration from a human readable string of characters.
The supported syntax for durations consists in a comma separated list of time values, followed by their respective time unit. Alternatively, the “and” keyword can be used in place of a comma. While time values are only accepted in their numerical form, time units are accepted in both their singular and plural forms.
If the provided string cannot’ be parsed, a ParseError will be
returned as part of the Result.
Reference
The accepted time units formats are as follows:
- Years:
years,yearandyare accepted - Months:
months,month, andmoare accepted - Weeks:
weeks,week, andware accepted - Days:
days,day, anddare accepted - Hours:
hours,hour, andhare accepted - Minutes:
minutesmins, andminare accepted - Seconds:
seconds,second,secs,secandsare accepted - Milliseconds:
milliseconds,millisecond,msare accepted - Nanoseconds:
nanoseconds,nanosecond,nsare accepted
Examples
use jackdauer::duration; // Singular let nanoseconds = duration("1 nanosecond"); // Plural let milliseconds = duration("2 milliseconds"); // Full syntax example let small = duration("3 seconds, 2 milliseconds and 1 nanosecond");