pub struct RetryPolicy {
pub max_retries: u32,
pub backoff_initial: Duration,
pub backoff_max: Duration,
pub backoff_jitter: f64,
pub http_statuses: BTreeSet<u16>,
pub respect_retry_after: bool,
pub max_retry_after: Option<Duration>,
pub api_connection_error: bool,
pub api_timeout_error: bool,
pub predicate: Option<RetryPredicate>,
pub timeout: Option<Duration>,
}Expand description
Configuration shared by synchronous and asynchronous request retries.
max_retries counts retries after the initial attempt. The optional timeout
budget includes requests and waits; a retry whose delay reaches the budget is
skipped. Request timeouts are configured separately on the client.
Fields§
§max_retries: u32Maximum retries after the initial attempt. Zero disables retries.
backoff_initial: DurationFirst exponential backoff delay. Zero disables backoff.
backoff_max: DurationMaximum exponential backoff delay. Zero disables backoff.
backoff_jitter: f64Fraction of each backoff randomly subtracted, between zero and one.
http_statuses: BTreeSet<u16>HTTP status codes that trigger a retry.
respect_retry_after: boolHonor Retry-After and retry-after-ms response headers.
max_retry_after: Option<Duration>Maximum accepted server delay. Larger hints fall back to backoff.
None accepts any representable server delay.
api_connection_error: boolRetry request connection and response-body delivery failures.
api_timeout_error: boolRetry request timeouts, independently from connection failures.
predicate: Option<RetryPredicate>Optional additional retry rule; built-in rules still apply. Cancellation is never retried, including by this predicate.
timeout: Option<Duration>Total retry budget including the first request, or None for no limit.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn no_retries() -> Self
pub fn no_retries() -> Self
A policy with no retries, retaining the other defaults.
Sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Validate jitter, status codes, and timer-compatible delays and budget.
Sourcepub fn should_retry(&self, error: &Error) -> bool
pub fn should_retry(&self, error: &Error) -> bool
Whether the error matches a built-in or additional retry rule.
This checks error classification only. The request loop separately applies the attempt limit and retry budget.
Sourcepub fn delay(&self, attempt: u32, headers: Option<&HeaderMap>) -> Duration
pub fn delay(&self, attempt: u32, headers: Option<&HeaderMap>) -> Duration
Delay before a zero-based retry attempt, honoring permitted server hints.
Attempt zero uses backoff_initial, attempt one twice that value, and so
on up to backoff_max, with random downward jitter. Very large attempt
numbers and header values are handled without arithmetic overflow.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more