atomic-circuit-breaker 11.2.0

Zero-dependency, lock-free atomic sliding-window circuit breaker with CAS probe gating, monotonic clock support, and RAII guards.
Documentation
use super::*;

/// Configuration validation errors returned when building a `CircuitBreaker`.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum CircuitBreakerError {
    /// Neither failure threshold, consecutive failure threshold, nor failure rate was enabled.
    NoTripCondition,
    /// A failure threshold was set to zero.
    InvalidThreshold,
    /// Failure rate was NaN, infinite, `<= 0.0`, or `> 1.0`.
    InvalidFailureRate,
    /// Sliding window duration was zero.
    ZeroWindow,
    /// Open cooldown duration was zero.
    ZeroCooldown,
    /// Half-open max probes was zero or success threshold exceeded max probes.
    InvalidHalfOpenConfig,
    /// Duration overflowed `u64::MAX` nanoseconds.
    DurationOverflow,
}

/// Error returned by `CircuitBreaker::call`, distinguishing rejections from inner errors.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum CallError<E> {
    /// Circuit was open or half-open probe capacity was saturated.
    Rejected {
        /// Current circuit state at rejection time.
        state: CircuitState,
        /// Nanoseconds remaining before cooldown expires (`0` if half-open saturated).
        retry_after_ns: u64,
    },
    /// The wrapped operation executed and returned an inner error.
    Inner(E),
}