Skip to content

feat(humantime): add support for Option<Duration> with serde_humantime#375

Merged
robjtede merged 1 commit intomainfrom
option-humantime-serde
Mar 19, 2026
Merged

feat(humantime): add support for Option<Duration> with serde_humantime#375
robjtede merged 1 commit intomainfrom
option-humantime-serde

Conversation

@tenuous-guidance
Copy link
Contributor

@tenuous-guidance tenuous-guidance commented Mar 16, 2026

Whilst Duration itself has an Option builder, which serde_humantime already handles, Option uses OptionBuilder, which serde_humantime does not support

Summary by CodeRabbit

  • New Features

    • Added an optional "humantime" feature to enable human-readable duration support in config parsing.
  • Tests

    • Added tests covering parsing of human-readable duration strings.
  • Documentation

    • Updated changelog with usage example for the new humantime feature.

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

Adds an optional humantime feature to confik that wires in humantime-serde, exposes a conditional public re-export, and provides serde helpers for Option<Duration> with accompanying tests and changelog entry.

Changes

Cohort / File(s) Summary
Feature / Manifest
confik/Cargo.toml
Added humantime feature mapping to dep:humantime-serde; declared humantime-serde as an optional dependency and as a dev-dependency (v1).
Public API / Re-exports
confik/src/lib.rs
Added #[cfg(feature = "humantime")] pub use self::third_party::humantime; to conditionally expose the humantime helpers.
humantime helpers
confik/src/third_party.rs
Added pub mod humantime (behind humantime feature) with option submodule providing serialize and deserialize functions for OptionBuilder<Option<Duration>> that delegate to humantime_serde helpers.
Tests
confik/tests/third_party.rs
Added feature-gated test (humantime + toml) that parses timeout = "1h 42m" and asserts the resulting Duration (6120s).
Changelog
confik/CHANGELOG.md
Added Unreleased entry documenting the new confik::humantime serde helpers and usage example.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through crates and feature trees,
Found humantime hiding in Cargo keys.
Option by option, durations now play,
Serde sings seconds in a friendly display.
— a small rabbit, testing all day 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding support for Option serialization with serde_humantime through a new humantime feature flag.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch option-humantime-serde
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Whilst Duration itself has an Option<Duration> builder, which serde_humantime already handles, Option<Duration> uses OptionBuilder<Duration>, which serde_humantime does not support
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
confik/tests/third_party.rs (1)

7-26: Test coverage is limited to the happy path.

The test validates parsing a present duration value but doesn't cover:

  • Missing timeout field (should result in None)
  • Behavior when the field is explicitly absent

Consider adding test cases for these scenarios to ensure the OptionBuilder handling works correctly for all cases.

🧪 Suggested additional test cases
#[test]
fn from_humantime_option_missing() {
    #[derive(Debug, PartialEq, Eq, Configuration)]
    struct Config {
        #[confik(forward(serde(with = "confik::humantime::option")))]
        timeout: Option<Duration>,
    }

    let config = ConfigBuilder::<Config>::default()
        .override_with(TomlSource::new(""))
        .try_build()
        .unwrap();

    assert_eq!(config, Config { timeout: None });
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@confik/tests/third_party.rs` around lines 7 - 26, Add negative-path tests for
the humantime option handling: create tests named like
from_humantime_option_missing and from_humantime_option_explicit_none that use
the same Config struct (with #[confik(forward(serde(with =
"confik::humantime::option")))] timeout: Option<Duration>) and build via
ConfigBuilder::<Config>::default().override_with(TomlSource::new(...)).try_build().unwrap();
for the missing case pass an empty source ("" ) and assert Config { timeout:
None }, and for the explicit-absent case pass a TOML that sets timeout = none
(or deletes the key) and assert None; add these new tests alongside
from_humantime_option to ensure OptionBuilder and the serde wrapper handle
absent/explicit-null correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@confik/tests/third_party.rs`:
- Around line 7-26: Add negative-path tests for the humantime option handling:
create tests named like from_humantime_option_missing and
from_humantime_option_explicit_none that use the same Config struct (with
#[confik(forward(serde(with = "confik::humantime::option")))] timeout:
Option<Duration>) and build via
ConfigBuilder::<Config>::default().override_with(TomlSource::new(...)).try_build().unwrap();
for the missing case pass an empty source ("" ) and assert Config { timeout:
None }, and for the explicit-absent case pass a TOML that sets timeout = none
(or deletes the key) and assert None; add these new tests alongside
from_humantime_option to ensure OptionBuilder and the serde wrapper handle
absent/explicit-null correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c698f400-f4c8-4df5-9bb8-e48b55740000

📥 Commits

Reviewing files that changed from the base of the PR and between 95a47bb and c94b381.

📒 Files selected for processing (5)
  • confik/CHANGELOG.md
  • confik/Cargo.toml
  • confik/src/lib.rs
  • confik/src/third_party.rs
  • confik/tests/third_party.rs
✅ Files skipped from review due to trivial changes (1)
  • confik/CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • confik/Cargo.toml

@robjtede robjtede merged commit 8a43506 into main Mar 19, 2026
9 checks passed
@robjtede robjtede deleted the option-humantime-serde branch March 19, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants