pub struct CircuitBreaker { /* private fields */ }Expand description
A named circuit breaker with metrics tracking.
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(name: impl Into<String>, config: CircuitConfig) -> Self
pub fn new(name: impl Into<String>, config: CircuitConfig) -> Self
Create a new circuit breaker with the given name and config.
Sourcepub fn with_defaults(name: impl Into<String>) -> Self
pub fn with_defaults(name: impl Into<String>) -> Self
Create with default config.
Sourcepub async fn call<F, Fut, T, E>(&self, f: F) -> Result<T, CircuitError<E>>
pub async fn call<F, Fut, T, E>(&self, f: F) -> Result<T, CircuitError<E>>
Execute an async operation through the circuit breaker.
Takes a closure that returns a Future, allowing lazy evaluation.
Sourcepub fn calls_total(&self) -> u64
pub fn calls_total(&self) -> u64
Get total number of calls.
Sourcepub fn rejections(&self) -> u64
pub fn rejections(&self) -> u64
Get number of rejected calls (circuit open).
Sourcepub fn failure_rate(&self) -> f64
pub fn failure_rate(&self) -> f64
Get failure rate (0.0 - 1.0).
Sourcepub fn is_likely_open(&self) -> bool
pub fn is_likely_open(&self) -> bool
Check if circuit is likely open (based on recent rejections).
Sourcepub fn reset_metrics(&self)
pub fn reset_metrics(&self)
Reset all metrics.
Auto Trait Implementations§
impl !Freeze for CircuitBreaker
impl !RefUnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin for CircuitBreaker
impl !UnwindSafe for CircuitBreaker
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> 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