pub struct CircuitBreaker { /* private fields */ }Expand description
按 host 分键的熔断器。clone() 共享同一份状态(内部 Arc)。
Implementations§
Source§impl CircuitBreaker
impl CircuitBreaker
Sourcepub fn new(config: CircuitBreakerConfig) -> Result<Self, BaseError>
pub fn new(config: CircuitBreakerConfig) -> Result<Self, BaseError>
用给定策略创建熔断器。
Sourcepub fn allow(&self, host: &str) -> bool
pub fn allow(&self, host: &str) -> bool
请求发送前的准入检查。true 放行,false 表示熔断打开应直接拒绝。
冷却结束的 Open 会在此转为 HalfOpen 并放行探测。
Sourcepub fn on_success(&self, host: &str)
pub fn on_success(&self, host: &str)
记录一次成功(2xx/3xx/4xx)。HalfOpen 下累计成功,达阈值恢复 Closed。
Sourcepub fn on_failure(&self, host: &str)
pub fn on_failure(&self, host: &str)
记录一次失败(传输错误或 5xx)。达阈值/半开失败 → 打开熔断。
Trait Implementations§
Source§impl Clone for CircuitBreaker
impl Clone for CircuitBreaker
Auto Trait Implementations§
impl Forget for CircuitBreaker
impl Freeze for CircuitBreaker
impl RefUnwindSafe for CircuitBreaker
impl Send for CircuitBreaker
impl Sync for CircuitBreaker
impl Unpin for CircuitBreaker
impl UnsafeUnpin 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> 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