Struct retry_future::ExponentialRetryStrategy
source · [−]pub struct ExponentialRetryStrategy {
pub base: usize,
pub max_attempts: usize,
pub initial_delay: Duration,
pub retry_early_returned_errors: bool,
}Expand description
Retry futures exponentially.
Examples
use retry_future::RetryStrategy;
use retry_future::ExponentialRetryStrategy;
use std::time::Duration;
let mut strategy = ExponentialRetryStrategy {
base: 3,
max_attempts: 5,
initial_delay: Duration::from_secs(1),
..Default::default()
};
assert_eq!(strategy.check_attempt(0).unwrap(), Duration::from_secs(1));
assert_eq!(strategy.check_attempt(1).unwrap(), Duration::from_secs(3));
assert_eq!(strategy.check_attempt(2).unwrap(), Duration::from_secs(9));
assert_eq!(strategy.check_attempt(3).unwrap(), Duration::from_secs(27));
assert_eq!(strategy.check_attempt(4).unwrap(), Duration::from_secs(81));
assert!(strategy.check_attempt(5).is_err());Fields
base: usizemax_attempts: usizeinitial_delay: Durationretry_early_returned_errors: boolImplementations
sourceimpl ExponentialRetryStrategy
impl ExponentialRetryStrategy
pub fn new() -> Self
pub fn max_attempts(self, max_attempts: usize) -> Self
pub fn initial_delay(self, initial_delay: Duration) -> Self
sourcepub fn retry_early_returned_errors(
self,
retry_early_returned_errors: bool
) -> Self
pub fn retry_early_returned_errors(
self,
retry_early_returned_errors: bool
) -> Self
Trait Implementations
sourceimpl Clone for ExponentialRetryStrategy
impl Clone for ExponentialRetryStrategy
sourcefn clone(&self) -> ExponentialRetryStrategy
fn clone(&self) -> ExponentialRetryStrategy
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresourceimpl Debug for ExponentialRetryStrategy
impl Debug for ExponentialRetryStrategy
sourceimpl Default for ExponentialRetryStrategy
impl Default for ExponentialRetryStrategy
sourceimpl RetryStrategy for ExponentialRetryStrategy
impl RetryStrategy for ExponentialRetryStrategy
sourcefn check_attempt(
&mut self,
attempts_before: usize
) -> Result<Duration, TooManyAttempts>
fn check_attempt(
&mut self,
attempts_before: usize
) -> Result<Duration, TooManyAttempts>
sourcefn retry_early_returned_errors(&self) -> bool
fn retry_early_returned_errors(&self) -> bool
impl Copy for ExponentialRetryStrategy
Auto Trait Implementations
impl RefUnwindSafe for ExponentialRetryStrategy
impl Send for ExponentialRetryStrategy
impl Sync for ExponentialRetryStrategy
impl Unpin for ExponentialRetryStrategy
impl UnwindSafe for ExponentialRetryStrategy
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more