use crate::compat::Duration;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RetryState {
pub attempt: u32,
pub elapsed: Option<Duration>,
pub previous_delay: Option<Duration>,
}
impl RetryState {
#[must_use]
pub const fn for_attempt(attempt: u32) -> Self {
debug_assert!(attempt >= 1, "attempt is 1-indexed");
Self {
attempt,
elapsed: None,
previous_delay: None,
}
}
#[must_use]
pub const fn with_elapsed(mut self, elapsed: Option<Duration>) -> Self {
self.elapsed = elapsed;
self
}
#[must_use]
pub const fn with_previous_delay(mut self, previous_delay: Option<Duration>) -> Self {
self.previous_delay = previous_delay;
self
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub struct AttemptState<'a, T, E> {
pub attempt: u32,
pub elapsed: Option<Duration>,
pub outcome: &'a Result<T, E>,
pub next_delay: Option<Duration>,
}
impl<'a, T, E> AttemptState<'a, T, E> {
#[must_use]
pub const fn for_attempt(attempt: u32, outcome: &'a Result<T, E>) -> Self {
debug_assert!(attempt >= 1, "attempt is 1-indexed");
Self {
attempt,
elapsed: None,
outcome,
next_delay: None,
}
}
#[must_use]
pub const fn with_elapsed(mut self, elapsed: Option<Duration>) -> Self {
self.elapsed = elapsed;
self
}
#[must_use]
pub const fn with_next_delay(mut self, next_delay: Option<Duration>) -> Self {
self.next_delay = next_delay;
self
}
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub struct ExitState<'a, T, E> {
pub attempt: u32,
pub elapsed: Option<Duration>,
pub outcome: &'a Result<T, E>,
pub stop_reason: crate::stats::StopReason,
}
impl<'a, T, E> ExitState<'a, T, E> {
#[must_use]
pub const fn for_attempt(
attempt: u32,
outcome: &'a Result<T, E>,
stop_reason: crate::stats::StopReason,
) -> Self {
debug_assert!(attempt >= 1, "attempt is 1-indexed");
Self {
attempt,
elapsed: None,
outcome,
stop_reason,
}
}
#[must_use]
pub const fn with_elapsed(mut self, elapsed: Option<Duration>) -> Self {
self.elapsed = elapsed;
self
}
}