pub struct RetryPolicy { /* private fields */ }Expand description
Retry policy with exponential backoff for transient failures.
Created via RetryPolicy::new with the maximum number of retries.
All other parameters have sensible defaults and can be customised with
builder methods.
§Defaults
| Parameter | Default |
|---|---|
max_retries | (required) |
initial_backoff | 200ms |
max_backoff | 30s |
multiplier | 2.0 |
§Examples
use std::time::Duration;
use ironflow_core::retry::RetryPolicy;
let policy = RetryPolicy::new(3)
.backoff(Duration::from_millis(100))
.max_backoff(Duration::from_secs(10))
.multiplier(3.0);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 number of retries.
The initial attempt is not counted as a retry, so max_retries(3) means
up to 4 total attempts (1 initial + 3 retries).
§Panics
Panics if max_retries is 0.
§Examples
use ironflow_core::retry::RetryPolicy;
let policy = RetryPolicy::new(3);
assert_eq!(policy.max_retries(), 3);Sourcepub fn backoff(self, duration: Duration) -> Self
pub fn backoff(self, duration: Duration) -> Self
Set the initial backoff duration before the first retry.
Subsequent retries multiply this duration by the multiplier.
§Panics
Panics if duration is zero.
Sourcepub fn max_backoff(self, duration: Duration) -> Self
pub fn max_backoff(self, duration: Duration) -> Self
Set the maximum backoff duration between retries.
Even after many retries with exponential growth, the delay will never exceed this value.
§Panics
Panics if duration is zero.
Sourcepub fn multiplier(self, multiplier: f64) -> Self
pub fn multiplier(self, multiplier: f64) -> Self
Set the backoff multiplier applied after each retry.
For example, with multiplier(2.0) and backoff(200ms):
- Retry 1: 200ms
- Retry 2: 400ms
- Retry 3: 800ms
§Panics
Panics if multiplier is less than 1.0, NaN, or infinity.
Sourcepub fn max_retries(&self) -> u32
pub fn max_retries(&self) -> u32
Return the maximum number of retries.
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more