use std::time::Duration;
#[derive(Debug)]
pub struct RetryConfig<E> {
pub max_attempts: usize,
pub delay: Duration,
pub retry_condition: Option<fn(&E) -> bool>,
}
impl<E> Default for RetryConfig<E> {
fn default() -> Self {
RetryConfig {
max_attempts: 3,
delay: Duration::from_secs(2),
retry_condition: None,
}
}
}
impl<E> RetryConfig<E> {
pub fn new(max_attempts: usize, delay: Duration) -> Self {
RetryConfig {
max_attempts,
delay,
retry_condition: None,
}
}
pub fn with_retry_condition(mut self, retry_condition: fn(&E) -> bool) -> Self {
self.retry_condition = Some(retry_condition);
self
}
}