Expand description
Go time.Duration string parsing.
A small, dependency-free primitive that parses duration strings in the exact format accepted by Go’s
time.ParseDuration. The Datadog Agent (via spf13/viper and spf13/cast) coerces
configuration values into Go durations, and several places in Saluki need to interpret those same strings,
including the runtime configuration layer and build-time config-schema codegen. This crate is the single owner of
that algorithm so it isn’t duplicated in each of those places.
Two entry points are provided: parse_duration accepts only Go’s strict time.ParseDuration grammar, while
parse_duration_or_nanos adds viper/cast’s coercion where a unit-less bare integer string (for example "30")
is read as that many nanoseconds. Callers that need Agent-compatible configuration coercion should use the latter.
Enums§
- Parse
Duration Error - Error returned when a duration string can’t be parsed.
Constants§
- MAX_
DURATION_ NANOS - Maximum nanosecond value accepted for compatibility with Go’s
time.Duration.
Functions§
- parse_
duration - Parses a string in the exact format accepted by Go’s
time.ParseDuration, restricted to non-negative values (sincestd::time::Durationcan’t represent negatives). - parse_
duration_ or_ nanos - Parses a duration string the way the Datadog Agent does: first as a strict Go duration via
parse_duration, then as a bare integer count of nanoseconds when the trimmed input contains only an integer. For example,"30"becomes 30 nanoseconds. Surrounding whitespace is ignored.