feat(seatbelt): introduce config for each middleware#302
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #302 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 144 147 +3
Lines 8921 9004 +83
=======================================
+ Hits 8921 9004 +83 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
geeknoid
approved these changes
Mar 4, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds serde-compatible configuration structs and .config() convenience methods to seatbelt middleware so users can load resilience settings from external config files (resolves #301).
Changes:
- Introduce
RetryConfig,BreakerConfig, andTimeoutConfig(serde-gated) and expose them from their modules. - Add
.config(&...Config)methods onRetryLayer,BreakerLayer, andTimeoutLayerto apply config in one call; refactor enable/disable handling via a sharedEnableIfenum. - Add a
configexample (JSON + Rust) and snapshot tests verifying defaults and config application.
Reviewed changes
Copilot reviewed 32 out of 33 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/seatbelt/src/utils/mod.rs | Replace macro-based EnableIf with an enum supporting enabled/disabled/custom predicate. |
| crates/seatbelt/src/timeout/mod.rs | Add config module and re-export TimeoutConfig. |
| crates/seatbelt/src/timeout/layer.rs | Add TimeoutLayer::config and update enable/disable plumbing + snapshots in tests. |
| crates/seatbelt/src/timeout/config.rs | New serde-gated TimeoutConfig with duration-friendly serde formatting. |
| crates/seatbelt/src/timeout/snapshots/* | New snapshots for timeout defaults and config application. |
| crates/seatbelt/src/retry/mod.rs | Add config module and re-export RetryConfig. |
| crates/seatbelt/src/retry/layer.rs | Add RetryLayer::config applying all config fields. |
| crates/seatbelt/src/retry/config.rs | New serde-gated RetryConfig with duration-friendly serde formatting. |
| crates/seatbelt/src/retry/backoff.rs | Add serde derives for Backoff (feature-gated). |
| crates/seatbelt/src/retry/service.rs | Switch default assertions to snapshots. |
| crates/seatbelt/src/retry/snapshots/* | New snapshots for retry defaults and config application. |
| crates/seatbelt/src/breaker/mod.rs | Add config module and re-export BreakerConfig. |
| crates/seatbelt/src/breaker/layer.rs | Add BreakerLayer::config applying all config fields. |
| crates/seatbelt/src/breaker/service.rs | Switch default assertions to snapshots. |
| crates/seatbelt/src/breaker/config.rs | New serde-gated BreakerConfig with duration-friendly serde formatting. |
| crates/seatbelt/src/breaker/half_open_mode.rs | Add serde representation for HalfOpenMode + serde roundtrip tests. |
| crates/seatbelt/src/breaker/snapshots/* | New snapshots for breaker defaults and config application. |
| crates/seatbelt/src/fallback/layer.rs | Update enable/disable plumbing to new EnableIf. |
| crates/seatbelt/src/lib.rs | Document new serde feature. |
| crates/seatbelt/examples/config.rs | New example showing deserialization + .config() usage. |
| crates/seatbelt/examples/config.json | Example JSON config file. |
| crates/seatbelt/README.md | Document new serde feature. |
| crates/seatbelt/Cargo.toml | Add serde feature, deps (serde, jiff), dev deps (insta, serde_json), and example wiring. |
| Cargo.lock | Lockfile updates for new dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
afoxman
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #301