#[cfg(feature = "alloc")]
use crate::compat::Box;
use crate::compat::Duration;
use crate::state::RetryState;
mod composition;
mod math;
mod strategies;
mod jitter;
pub use composition::{WaitCapped, WaitChain, WaitCombine};
pub use jitter::Jittered;
pub use jitter::WaitDecorrelatedJitter;
pub use jitter::decorrelated_jitter;
pub use strategies::{WaitExponential, WaitFixed, WaitLinear, exponential, fixed, linear};
pub trait Wait {
fn next_wait(&self, state: &RetryState) -> Duration;
#[must_use]
fn cap(self, max: Duration) -> WaitCapped<Self>
where
Self: Sized,
{
WaitCapped { inner: self, max }
}
#[must_use]
fn chain<W2: Wait>(self, other: W2, after: u32) -> WaitChain<Self, W2>
where
Self: Sized,
{
WaitChain::new(self, other, after)
}
#[must_use]
fn add<W2: Wait>(self, other: W2) -> WaitCombine<Self, W2>
where
Self: Sized,
{
WaitCombine::new(self, other)
}
#[must_use]
fn jitter(self, max_jitter: Duration) -> Jittered<Self>
where
Self: Sized,
{
Jittered::additive(self, max_jitter)
}
#[must_use]
fn full_jitter(self) -> Jittered<Self>
where
Self: Sized,
{
Jittered::full(self)
}
#[must_use]
fn equal_jitter(self) -> Jittered<Self>
where
Self: Sized,
{
Jittered::equal(self)
}
}
#[cfg(feature = "alloc")]
impl<W> Wait for Box<W>
where
W: Wait + ?Sized,
{
fn next_wait(&self, state: &RetryState) -> Duration {
(**self).next_wait(state)
}
}