pub struct RetryPolicy {
pub max_retries: u32,
pub backoff_base: Duration,
pub backoff_max: Duration,
pub retryable_status_codes: HashSet<u16>,
pub retry_on_connection_error: bool,
pub retry_on_timeout: bool,
}Expand description
Configuration for automatic request retries.
Fields§
§max_retries: u32Maximum number of retry attempts.
backoff_base: DurationBase delay for exponential backoff (e.g. 100ms).
backoff_max: DurationMaximum delay between retries.
retryable_status_codes: HashSet<u16>HTTP status codes that trigger a retry.
retry_on_connection_error: boolWhether to retry on connection errors.
retry_on_timeout: boolWhether to retry on timeout errors.
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new(max_retries: u32) -> Self
pub fn new(max_retries: u32) -> Self
Create a new retry policy with the given maximum retry count.
Sourcepub fn with_backoff_base(self, base: Duration) -> Self
pub fn with_backoff_base(self, base: Duration) -> Self
Set the base delay for exponential backoff.
Sourcepub fn with_backoff_max(self, max: Duration) -> Self
pub fn with_backoff_max(self, max: Duration) -> Self
Set the maximum delay between retries.
Sourcepub fn with_retryable_status_codes(self, codes: HashSet<u16>) -> Self
pub fn with_retryable_status_codes(self, codes: HashSet<u16>) -> Self
Set the retryable status codes.
Sourcepub fn add_retryable_status(self, code: u16) -> Self
pub fn add_retryable_status(self, code: u16) -> Self
Add a retryable status code.
Sourcepub fn with_retry_on_connection_error(self, retry: bool) -> Self
pub fn with_retry_on_connection_error(self, retry: bool) -> Self
Set whether to retry on connection errors.
Sourcepub fn with_retry_on_timeout(self, retry: bool) -> Self
pub fn with_retry_on_timeout(self, retry: bool) -> Self
Set whether to retry on timeout errors.
Sourcepub fn should_retry_status(&self, status_code: u16) -> bool
pub fn should_retry_status(&self, status_code: u16) -> bool
Returns true if the given status code should trigger a retry.
Sourcepub fn backoff_delay(&self, attempt: u32) -> Duration
pub fn backoff_delay(&self, attempt: u32) -> Duration
Calculate the backoff delay for the given attempt number (0-indexed).
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
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 RetryPolicy
impl Debug for RetryPolicy
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnsafeUnpin for RetryPolicy
impl UnwindSafe for RetryPolicy
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