pub struct ExponentialBackoff {
pub initial_delay: Duration,
pub max_delay: Duration,
pub max_attempts: u32,
pub multiplier: f64,
}Expand description
Exponential backoff retry policy.
Each retry waits exponentially longer than the previous one, up to a maximum delay. This is the recommended policy for most network operations.
§Example
use error_rail::async_ext::ExponentialBackoff;
use core::time::Duration;
let policy = ExponentialBackoff {
initial_delay: Duration::from_millis(100),
max_delay: Duration::from_secs(10),
max_attempts: 5,
multiplier: 2.0,
};
// Delays: 100ms, 200ms, 400ms, 800ms, 1600ms (capped at 10s)Fields§
§initial_delay: DurationInitial delay before first retry.
max_delay: DurationMaximum delay between retries.
max_attempts: u32Maximum number of retry attempts.
multiplier: f64Multiplier applied to delay after each attempt.
Implementations§
Source§impl ExponentialBackoff
impl ExponentialBackoff
Sourcepub fn with_initial_delay(self, delay: Duration) -> Self
pub fn with_initial_delay(self, delay: Duration) -> Self
Sets the initial delay.
Sourcepub fn with_max_delay(self, delay: Duration) -> Self
pub fn with_max_delay(self, delay: Duration) -> Self
Sets the maximum delay.
Sourcepub fn with_max_attempts(self, attempts: u32) -> Self
pub fn with_max_attempts(self, attempts: u32) -> Self
Sets the maximum number of attempts.
Sourcepub fn with_multiplier(self, multiplier: f64) -> Self
pub fn with_multiplier(self, multiplier: f64) -> Self
Sets the multiplier.
Trait Implementations§
Source§impl Clone for ExponentialBackoff
impl Clone for ExponentialBackoff
Source§fn clone(&self) -> ExponentialBackoff
fn clone(&self) -> ExponentialBackoff
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ExponentialBackoff
impl Debug for ExponentialBackoff
Source§impl Default for ExponentialBackoff
impl Default for ExponentialBackoff
Source§impl RetryPolicy for ExponentialBackoff
impl RetryPolicy for ExponentialBackoff
Auto Trait Implementations§
impl Freeze for ExponentialBackoff
impl RefUnwindSafe for ExponentialBackoff
impl Send for ExponentialBackoff
impl Sync for ExponentialBackoff
impl Unpin for ExponentialBackoff
impl UnwindSafe for ExponentialBackoff
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)