use std::time;
pub const DEFAULT_MIN_DURATION: time::Duration = time::Duration::from_millis(100);
#[derive(Clone, Debug)]
pub struct RetryState {
pub wait: Option<time::Duration>,
pub total_allowed: u32,
pub attempt: u32,
}
impl RetryState {
#[must_use]
pub fn new(attempt: u32, total_allowed: u32, wait: Option<time::Duration>) -> Self {
Self {
wait,
total_allowed,
attempt,
}
}
#[must_use]
pub fn can_retry(&self) -> bool {
self.attempt == self.total_allowed
}
}
pub trait RetryDecider {
fn decide(&self, state: RetryState) -> Option<RetryState>;
}
pub trait CReconnectionDecider: RetryDecider {
fn clone_box(&self) -> Box<dyn CReconnectionDecider>;
}
impl<T> CReconnectionDecider for T
where
T: RetryDecider + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn CReconnectionDecider> {
Box::new(self.clone())
}
}