pub struct Exponential { /* private fields */ }Expand description
Exponential backoff delay.
Each retry multiplies the delay by multiplier (default 2),
capped at max (default 60s). Optional jitter applies
±25% random variation to each delay value.
§Example
use std::time::Duration;
use retry::delay::{Delay, Exponential};
let mut d = Exponential::new(Duration::from_millis(100))
.with_max(Duration::from_secs(2))
.with_multiplier(2);
assert_eq!(d.next_delay(), Duration::from_millis(100));
assert_eq!(d.next_delay(), Duration::from_millis(200));
assert_eq!(d.next_delay(), Duration::from_millis(400));
assert_eq!(d.next_delay(), Duration::from_millis(800));
assert_eq!(d.next_delay(), Duration::from_millis(1600));
// capped at max
assert_eq!(d.next_delay(), Duration::from_secs(2));
assert_eq!(d.next_delay(), Duration::from_secs(2));Implementations§
Source§impl Exponential
impl Exponential
Sourcepub fn new(initial: Duration) -> Self
pub fn new(initial: Duration) -> Self
Creates a new exponential backoff starting with initial delay.
Sourcepub fn with_multiplier(self, multiplier: u32) -> Self
pub fn with_multiplier(self, multiplier: u32) -> Self
Sets the multiplier applied to the delay after each retry (default 2).
Sourcepub fn with_jitter(self) -> Self
pub fn with_jitter(self) -> Self
Enables ±25% random jitter on each delay value.
The actual delay will be uniformly distributed in the range
[0.75 * delay, 1.25 * delay].
Trait Implementations§
Source§impl Clone for Exponential
impl Clone for Exponential
Source§fn clone(&self) -> Exponential
fn clone(&self) -> Exponential
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 Exponential
impl Debug for Exponential
Source§impl Delay for Exponential
impl Delay for Exponential
Source§fn next_delay(&mut self) -> Duration
fn next_delay(&mut self) -> Duration
Returns the delay before the next retry attempt.
Auto Trait Implementations§
impl Freeze for Exponential
impl RefUnwindSafe for Exponential
impl Send for Exponential
impl Sync for Exponential
impl Unpin for Exponential
impl UnsafeUnpin for Exponential
impl UnwindSafe for Exponential
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