#[non_exhaustive]pub enum CircuitState {
Closed {
error_count: u32,
threshold: u32,
},
Open {
opened_at: MonoTime,
cooldown: Duration,
threshold: u32,
},
HalfOpen {
threshold: u32,
},
}Expand description
Circuit breaker state for a remote node or service.
Implements the standard closed/open/half-open pattern to prevent cascading failures when a remote node becomes unreachable.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Closed
Normal operation – requests flow through.
Open
Too many failures – requests blocked for cooldown.
HalfOpen
Testing if service has recovered (one probe allowed).
Implementations§
Source§impl CircuitState
impl CircuitState
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
Record a successful call. Resets to closed state.
Sourcepub fn record_failure(&mut self) -> bool
pub fn record_failure(&mut self) -> bool
Record a failed call. Returns true if the circuit just opened.
Uses the production RealClock. Prefer
Self::record_failure_at when a Clock is available.
Sourcepub fn record_failure_at(&mut self, clock: &dyn Clock) -> bool
pub fn record_failure_at(&mut self, clock: &dyn Clock) -> bool
Record a failure at clock.now().
Sourcepub fn is_allowed(&mut self) -> bool
pub fn is_allowed(&mut self) -> bool
Check if requests should be allowed through.
Uses the production RealClock. Prefer
Self::is_allowed_at when a Clock is available.
Sourcepub fn is_allowed_at(&mut self, clock: &dyn Clock) -> bool
pub fn is_allowed_at(&mut self, clock: &dyn Clock) -> bool
Check allowance using an injectable Clock.
- Closed: always allowed.
- Open: allowed only after cooldown expires (transitions to half-open).
- HalfOpen: allowed (probe request).
Trait Implementations§
Source§impl Clone for CircuitState
impl Clone for CircuitState
Auto Trait Implementations§
impl Freeze for CircuitState
impl RefUnwindSafe for CircuitState
impl Send for CircuitState
impl Sync for CircuitState
impl Unpin for CircuitState
impl UnsafeUnpin for CircuitState
impl UnwindSafe for CircuitState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more