Packages / rupm

rs-dev-circuit-breaker 0.1.0

Closed, open and half-open circuit breaker with failure thresholds, cool-down and an injectable clock

Install

cargo add rs-dev-circuit-breaker --registry rupm

In Ruststudio: Packages, search for rs-dev-circuit-breaker, Install.

Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.

Versions

README

# rs-dev-circuit-breaker

A circuit breaker with closed, open and half-open states, a failure threshold, a cool-down period and trial calls for recovery. Time comes from an injectable `Clock` trait, so behaviour is easy to test.

## Install

Add it with `rupm add rs-dev-circuit-breaker` (or `cargo add rs-dev-circuit-breaker --registry rupm`).

## Usage

```rust
use rs_dev_circuit_breaker::{Breaker, CallError, Config};

let mut breaker = Breaker::new(Config::default());
match breaker.call(|| Ok::<_, String>(42)) {
    Ok(v) => println!("got {v}"),
    Err(CallError::Rejected) => println!("breaker open"),
    Err(CallError::Failed(e)) => println!("failed: {e}"),
}
```

## API overview

- `Breaker::new`, `with_clock`, `allow`, `record_success`, `record_failure`, `call`, `state`, `retry_after`, `reset`
- `Config { failure_threshold, success_threshold, cooldown, half_open_max_calls }`
- `State`, `CallError`, `Clock`, `SystemClock`, `ManualClock`