parse
Parses a human-written duration such as "1h30m", "2d" or "500ms".
The input is one or more <integer><unit> pairs, optionally separated by whitespace, and their
sum is returned. Units are ms, s, m, h, d (24 hours) and w (7 days), and may
repeat or come in any order. A bare number, a fraction, a sign or an unknown unit is an error
with the byte offset where it was found. It is the inverse of format.
Import
Section titled “Import”Cargo feature duration (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | &str | The human-written duration, such as "1h30m". |
Returns
Section titled “Returns”Result<Duration, ParseDurationError> — Ok on success, otherwise an Err: see Errors.
Errors
Section titled “Errors”Returns a ParseDurationError when the input is empty, has something other than a number
where one is expected, a number without a unit, an unknown unit, or a total that does not fit
in a Duration.
Examples
Section titled “Examples”Error type: ParseDurationError
Section titled “Error type: ParseDurationError”Why a string could not be parsed as a duration.
