pub struct RetryConfig {
pub max_retries: u32,
pub retry_on: Vec<u16>,
pub backoff_ms: u64,
}Expand description
请求级重试策略配置(L-4)。
对临时性失败(连接错误、可重试的 5xx 等)按指数退避自动重试。
默认不重试——只有显式调用 RequestBuilder::retry 才启用。
注意:当前仅实现「重试 + 指数退避」。熔断(circuit breaker)尚未实现, 如需熔断请在调用方或网关层处理。
§示例
ⓘ
use yang_base::http::RetryConfig;
let cfg = RetryConfig {
max_retries: 3,
retry_on: vec![502, 503, 504],
backoff_ms: 100, // 第 n 次重试前等待 backoff_ms * 2^(n-1) 毫秒
};Fields§
§max_retries: u32最大重试次数(不含首次请求)。0 等价于不重试。
retry_on: Vec<u16>命中这些 HTTP 状态码时重试(如 [502, 503, 504])。
backoff_ms: u64初始退避毫秒数,按 backoff_ms * 2^attempt 指数增长。
Implementations§
Trait Implementations§
Source§impl Clone for RetryConfig
impl Clone for RetryConfig
Source§fn clone(&self) -> RetryConfig
fn clone(&self) -> RetryConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryConfig
impl Debug for RetryConfig
Auto Trait Implementations§
impl Freeze for RetryConfig
impl RefUnwindSafe for RetryConfig
impl Send for RetryConfig
impl Sync for RetryConfig
impl Unpin for RetryConfig
impl UnsafeUnpin for RetryConfig
impl UnwindSafe for RetryConfig
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