humantime-serde
Serde (de)serialization support for human-readable durations and timestamps
Repository Health
Technical Analysis
humantime-serde bridges the humantime crate’s human-friendly duration and timestamp parsing ("15days", "2h 30m") with Serde, so std::time::Duration and SystemTime fields can be read from and written to config files, JSON, or any Serde-backed format using readable strings instead of raw nanosecond integers.
It’s applied via a #[serde(with = "humantime_serde")] attribute on a struct field, or through a Serde<T> wrapper type for use inside collections like Vec<Serde<SystemTime>>, and has become a near-standard companion crate wherever configuration structs need human-readable time values.
What You Get
- A
#[serde(with = "humantime_serde")]attribute helper forDurationandSystemTimefields on any Serde-derived struct - An
optionsubmodule providing the same support forOption<Duration>/Option<SystemTime>fields - A
Serde<T>newtype wrapper for using humantime-formatted values inside collections likeVec<Serde<SystemTime>> - A re-exported
re::humantimemodule so consumers can reach the underlyinghumantimecrate without adding it as a direct dependency
Common Use Cases
- Reading timeout, TTL, or interval fields from a YAML/TOML/JSON config file as
"30s"or"5m"instead of raw integers - Serializing
SystemTimefields to human-readable timestamps in structured logs or config dumps - Building CLI tools or daemons whose configuration structs need human-editable duration fields with zero custom parsing code
- Composing with other Serde-derived structs in libraries that expose duration/time settings as part of their public config API
Under The Hood
Architecture — The crate is two small modules: src/lib.rs (~377 lines) implements top-level serialize/deserialize functions and the Serde<T> wrapper type using Deref/DerefMut to transparently expose the inner Duration/SystemTime, while src/option.rs (~47 lines) re-implements the same pair for Option<T> fields, since Serde’s with attribute needs distinct functions per Option-ness. Tech Stack — Minimal pure-Rust dependencies: humantime for the actual string parsing/formatting and serde (with the derive feature) for the (de)serialization traits; dev-dependencies add serde_json for doctests and version-sync to keep README version badges in sync with Cargo.toml. Code Quality — #![forbid(unsafe_code)] is set at the crate root, the public API is documented with runnable doctests demonstrating both the attribute and wrapper-type usage patterns, and lib.rs carries six #[test] functions covering round-trip serialization; the crate has seen no commits since its 1.1.1 release in 2022, though its narrow scope means little churn is expected. API Design — The #[serde(with = "humantime_serde")] attribute pattern requires no boilerplate beyond one derive annotation per field, making it a drop-in addition to existing Serde structs; the separate option module for Option<T> fields is the one wrinkle a user must discover before mixing optional and required time fields.
Used by 2 apps in this directory
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
Spacedrive
File Storage · Collaboration
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.