#[cfg(feature = "alloc")]
use crate::compat::Box;
use crate::state::RetryState;
mod composition;
mod strategies;
pub use composition::{StopAll, StopAny};
pub use strategies::{StopAfterAttempts, StopAfterElapsed, StopNever, attempts, elapsed, never};
pub trait Stop {
fn should_stop(&self, state: &RetryState) -> bool;
#[must_use]
fn or<S: Stop>(self, other: S) -> StopAny<Self, S>
where
Self: Sized,
{
StopAny::new(self, other)
}
#[must_use]
fn and<S: Stop>(self, other: S) -> StopAll<Self, S>
where
Self: Sized,
{
StopAll::new(self, other)
}
}
#[cfg(feature = "alloc")]
impl<S> Stop for Box<S>
where
S: Stop + ?Sized,
{
fn should_stop(&self, state: &RetryState) -> bool {
(**self).should_stop(state)
}
}