use std::time::Instant;
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct RetryState {
pub idempotent: bool,
pub start: Instant,
pub attempt_count: u32,
}
impl RetryState {
pub fn new(idempotent: bool) -> Self {
Self::default().set_idempotent(idempotent)
}
pub fn set_idempotent(mut self, v: bool) -> Self {
self.idempotent = v;
self
}
pub fn set_start<T: Into<Instant>>(mut self, v: T) -> Self {
self.start = v.into();
self
}
pub fn set_attempt_count<T: Into<u32>>(mut self, v: T) -> Self {
self.attempt_count = v.into();
self
}
}
impl std::default::Default for RetryState {
fn default() -> Self {
Self {
start: Instant::now(),
idempotent: false,
attempt_count: 0,
}
}
}