Skip to main content

RetryOptions

Struct RetryOptions 

Source
pub struct RetryOptions {
    pub max_attempts: NonZeroU32,
    pub max_elapsed: Option<Duration>,
    pub delay: RetryDelay,
    pub jitter: RetryJitter,
}
Expand description

Immutable retry option snapshot used by crate::RetryExecutor.

RetryOptions owns all executor configuration that is independent of the application error type: attempt limits, total elapsed-time budget, delay strategy, and jitter strategy. Construction validates the delay and jitter values before an executor can use them.

Fields§

§max_attempts: NonZeroU32

Maximum attempts, including the initial attempt.

§max_elapsed: Option<Duration>

Maximum total elapsed time for the retry flow, in milliseconds.

§delay: RetryDelay

Base delay strategy between attempts.

§jitter: RetryJitter

RetryJitter applied to each base delay.

Implementations§

Source§

impl RetryOptions

Source

pub const KEY_MAX_ATTEMPTS: &'static str = "max_attempts"

Key for maximum attempts.

Source

pub const KEY_MAX_ELAPSED_MILLIS: &'static str = "max_elapsed_millis"

Key for maximum elapsed budget in milliseconds. Missing means unlimited; zero also maps to unlimited when read from config.

Source

pub const KEY_DELAY: &'static str = "delay"

Key for delay strategy name.

Source

pub const KEY_DELAY_STRATEGY: &'static str = "delay_strategy"

Backward-compatible alias for delay strategy name.

Source

pub const KEY_FIXED_DELAY_MILLIS: &'static str = "fixed_delay_millis"

Key for fixed delay in milliseconds.

Source

pub const KEY_RANDOM_MIN_DELAY_MILLIS: &'static str = "random_min_delay_millis"

Key for random minimum delay in milliseconds.

Source

pub const KEY_RANDOM_MAX_DELAY_MILLIS: &'static str = "random_max_delay_millis"

Key for random maximum delay in milliseconds.

Source

pub const KEY_EXPONENTIAL_INITIAL_DELAY_MILLIS: &'static str = "exponential_initial_delay_millis"

Key for exponential initial delay in milliseconds.

Source

pub const KEY_EXPONENTIAL_MAX_DELAY_MILLIS: &'static str = "exponential_max_delay_millis"

Key for exponential maximum delay in milliseconds.

Source

pub const KEY_EXPONENTIAL_MULTIPLIER: &'static str = "exponential_multiplier"

Key for exponential multiplier.

Source

pub const KEY_JITTER_FACTOR: &'static str = "jitter_factor"

Key for jitter factor.

Source

pub fn new( max_attempts: u32, max_elapsed: Option<Duration>, delay: RetryDelay, jitter: RetryJitter, ) -> Result<Self, RetryConfigError>

Creates and validates a retry option snapshot.

§Parameters
  • max_attempts: Maximum number of attempts, including the first call. Must be greater than zero.
  • max_elapsed: Optional total elapsed-time budget for all attempts and sleeps.
  • delay: Base delay strategy used between attempts.
  • jitter: RetryJitter strategy applied to each base delay.
§Returns

A validated RetryOptions value.

§Errors

Returns RetryConfigError when max_attempts is zero, or when delay or jitter contains invalid parameters.

Source

pub fn from_config<R>(config: &R) -> Result<Self, RetryConfigError>
where R: ConfigReader + ?Sized,

Reads a retry option snapshot from a ConfigReader.

Keys are relative to the reader. Use config.prefix_view("retry") when the retry settings are nested under a retry. prefix.

§Parameters
  • config: Configuration reader whose keys are relative to the retry configuration prefix.
§Returns

A validated RetryOptions value. Missing keys fall back to RetryOptions::default.

§Errors

Returns RetryConfigError when a key cannot be read as the expected type, the delay strategy name is unsupported, or the resulting options fail validation.

Source

pub fn validate(&self) -> Result<(), RetryConfigError>

Validates all options.

§Returns

Ok(()) when all contained strategy parameters are usable.

§Parameters

This method has no parameters.

§Errors

Returns RetryConfigError with the relevant config key when the delay or jitter strategy is invalid.

Trait Implementations§

Source§

impl Clone for RetryOptions

Source§

fn clone(&self) -> RetryOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RetryOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RetryOptions

Source§

fn default() -> Self

Creates the default retry options.

§Returns

Options with three attempts, no total elapsed-time limit, exponential delay, and no jitter.

§Parameters

This function has no parameters.

§Errors

This function does not return errors.

§Panics

This function does not panic because the hard-coded attempt count is non-zero.

Source§

impl PartialEq for RetryOptions

Source§

fn eq(&self, other: &RetryOptions) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for RetryOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.