Skip to main content

Module parse

Module parse 

Source
Expand description

Shared human-duration parsing (#56).

One canonical parser feeds both the config layer ([slow_log] threshold) and CLI args (ferrule history --since), replacing the two near-identical inline parsers those call sites grew independently during the Query Telemetry Foundation sprint. It returns chrono::Duration so each caller maps to whatever unit it needs (milliseconds for the slow-log threshold, the raw delta for --since).

Recognised units — the union of the two original alias sets:

  • ms
  • s / sec / secs
  • m / min / mins
  • h / hr / hrs
  • d / day / days

A unit suffix is required: a bare integer ("500") is rejected here. Callers that assign a default unit to a bare integer (e.g. [slow_log] threshold = "500" → 500 ms) keep that quirk in their own thin wrapper, handled before delegating.

Out of scope, per #56 (kept here so the boundary is explicit):

  • The humantime crate — not worth the dependency at this caller count; revisit past ~5 callers.
  • Fractional units (1.5h, 0.5d) — unused anywhere; YAGNI.
  • A byte-size parser for [slow_log] max_size (#55) — same shape, distinct unit class; share structure, not this signature.

Functions§

parse_duration
Parse a human-readable duration like 250ms, 30s, 5m, 2h, or 7d into a chrono::Duration.
parse_size
Parse a human-readable byte size like 1024, 10MB, or 5MiB into a count of bytes.