pub enum RetryDelay {
None,
Fixed(Duration),
Random {
min: Duration,
max: Duration,
},
Exponential {
initial: Duration,
max: Duration,
multiplier: f64,
},
}Expand description
Base delay strategy before jitter is applied.
RetryDelay strategies are value types that can be reused across executors. Random
and exponential strategies are validated separately by RetryDelay::validate,
which is called when building crate::RetryOptions.
Variants§
None
Retry immediately.
Fixed(Duration)
Wait for a constant delay after every failed attempt.
Random
Pick a delay uniformly from the inclusive range.
Exponential
Exponential backoff capped by max.
Implementations§
Source§impl RetryDelay
impl RetryDelay
Sourcepub fn none() -> RetryDelay
pub fn none() -> RetryDelay
Creates a no-delay strategy.
§Parameters
This function has no parameters.
§Returns
A RetryDelay::None strategy.
§Errors
This function does not return errors.
Sourcepub fn fixed(delay: Duration) -> RetryDelay
pub fn fixed(delay: Duration) -> RetryDelay
Creates a fixed-delay strategy.
§Parameters
delay: Duration slept after each failed attempt.
§Returns
A RetryDelay::Fixed strategy.
§Errors
This constructor does not validate delay; use RetryDelay::validate to
reject a zero duration.
Sourcepub fn random(min: Duration, max: Duration) -> RetryDelay
pub fn random(min: Duration, max: Duration) -> RetryDelay
Creates a random-delay strategy.
§Parameters
min: Inclusive lower bound for generated delays.max: Inclusive upper bound for generated delays.
§Returns
A RetryDelay::Random strategy.
§Errors
This constructor does not validate the range; use RetryDelay::validate to
reject a zero minimum or a minimum greater than the maximum.
Sourcepub fn exponential(
initial: Duration,
max: Duration,
multiplier: f64,
) -> RetryDelay
pub fn exponential( initial: Duration, max: Duration, multiplier: f64, ) -> RetryDelay
Creates an exponential-backoff strategy.
§Parameters
initial: RetryDelay used for the first retry.max: Upper bound applied to every calculated delay.multiplier: Factor applied for each subsequent failed attempt.
§Returns
A RetryDelay::Exponential strategy.
§Errors
This constructor does not validate the parameters; use
RetryDelay::validate to reject a zero initial delay, max < initial, or
a multiplier that is non-finite or less than or equal to 1.0.
Sourcepub fn base_delay(&self, attempt: u32) -> Duration
pub fn base_delay(&self, attempt: u32) -> Duration
Calculates the base delay for an attempt number starting at 1.
Attempt 1 means the first failed attempt, so exponential backoff
returns initial for attempts 0 and 1. Random delays use a fresh
random value for every call.
§Parameters
attempt: Failed attempt number. Values0and1are treated as the first exponential-backoff step.
§Returns
The base delay before jitter is applied.
§Errors
This function does not return errors. Invalid strategies should be
rejected with RetryDelay::validate before they are used in an executor.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates strategy parameters.
Returns a human-readable message describing the invalid field when the strategy cannot be used safely by an executor.
§Returns
Ok(()) when all parameters are usable; otherwise an error message that
can be wrapped by crate::RetryConfigError.
§Parameters
This method has no parameters.
§Errors
Returns an error when a fixed delay is zero, a random range is invalid, or exponential backoff parameters are zero, inverted, non-finite, or too small.
Trait Implementations§
Source§impl Clone for RetryDelay
impl Clone for RetryDelay
Source§fn clone(&self) -> RetryDelay
fn clone(&self) -> RetryDelay
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RetryDelay
impl Debug for RetryDelay
Source§impl Default for RetryDelay
impl Default for RetryDelay
Source§fn default() -> RetryDelay
fn default() -> RetryDelay
Creates the default exponential-backoff strategy.
§Returns
The value obtained by parsing crate::constants::DEFAULT_RETRY_DELAY
using RetryDelay::from_str.
§Parameters
This function has no parameters.
§Errors
This function does not return errors.
§Panics
Panics if crate::constants::DEFAULT_RETRY_DELAY is not a valid
RetryDelay string. That indicates a crate bug, not a caller mistake.
Source§impl<'de> Deserialize<'de> for RetryDelay
impl<'de> Deserialize<'de> for RetryDelay
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RetryDelay, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RetryDelay, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for RetryDelay
impl Display for RetryDelay
Source§impl FromStr for RetryDelay
impl FromStr for RetryDelay
Source§type Err = ParseError
type Err = ParseError
Source§fn from_str(s: &str) -> Result<RetryDelay, <RetryDelay as FromStr>::Err>
fn from_str(s: &str) -> Result<RetryDelay, <RetryDelay as FromStr>::Err>
s to return a value of this type. Read moreSource§impl PartialEq for RetryDelay
impl PartialEq for RetryDelay
Source§fn eq(&self, other: &RetryDelay) -> bool
fn eq(&self, other: &RetryDelay) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for RetryDelay
impl Serialize for RetryDelay
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for RetryDelay
Auto Trait Implementations§
impl Freeze for RetryDelay
impl RefUnwindSafe for RetryDelay
impl Send for RetryDelay
impl Sync for RetryDelay
impl Unpin for RetryDelay
impl UnsafeUnpin for RetryDelay
impl UnwindSafe for RetryDelay
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> IntoValueDefault<T> for T
impl<T> IntoValueDefault<T> for T
Source§fn into_value_default(self) -> T
fn into_value_default(self) -> T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.