mod strategy;
pub use self::strategy::*;
use std::num::NonZeroU8;
use crate::FloatDuration;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Retry {
pub strategy: Strategy,
pub retry_limit: Option<NonZeroU8>,
}
impl Default for Retry {
fn default() -> Self {
Self {
strategy: Strategy::Backoff(ExponentialBackoff::default()),
retry_limit: Some(const { NonZeroU8::new(5).unwrap() }),
}
}
}
impl Retry {
pub(crate) fn retry_in(
&self,
last_wait: Option<FloatDuration>,
attempts: u8,
) -> Option<FloatDuration> {
if self.retry_limit.is_none_or(|a| attempts < a.get()) {
Some(self.strategy.retry_in(last_wait))
} else {
None
}
}
}