1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pub mod exponential;
pub mod infinite;
pub mod linear;
use std::time::Duration;
use crate::error::TooManyAttempts;
pub use exponential::ExponentialRetryStrategy;
pub use infinite::InfiniteRetryStrategy;
pub use linear::LinearRetryStrategy;
pub trait RetryStrategy {
fn check_attempt(&mut self, attempts_before: usize) -> Result<Duration, TooManyAttempts>;
fn retry_early_returned_errors(&self) -> bool;
}
impl<T> RetryStrategy for &mut T
where
T: RetryStrategy,
{
fn check_attempt(&mut self, attempts_before: usize) -> Result<Duration, TooManyAttempts> {
(*self).check_attempt(attempts_before)
}
fn retry_early_returned_errors(&self) -> bool {
(**self).retry_early_returned_errors()
}
}