Skip to main content

RetryOptions

Struct RetryOptions 

Source
pub struct RetryOptions { /* private fields */ }
Expand description

Immutable retry option snapshot used by crate::Retry.

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

Implementations§

Source§

impl RetryOptions

Source

pub fn max_attempts(&self) -> u32

Returns maximum attempts, including the initial attempt.

§Parameters

This method has no parameters.

§Returns

Maximum attempts configured for one retry execution.

§Errors

This method does not return errors.

Source

pub fn max_operation_elapsed(&self) -> Option<Duration>

Returns maximum cumulative user operation time budget.

§Parameters

This method has no parameters.

§Returns

Some(Duration) for bounded executions, or None for unlimited.

§Errors

This method does not return errors.

Source

pub fn max_total_elapsed(&self) -> Option<Duration>

Returns maximum total retry-flow elapsed time budget.

This budget is measured with monotonic time and includes operation execution, retry sleeps, retry-after sleeps, and retry control-path listener time.

§Parameters

This method has no parameters.

§Returns

Some(Duration) for bounded executions, or None for unlimited.

§Errors

This method does not return errors.

Source

pub fn delay(&self) -> &RetryDelay

Returns the base delay strategy.

§Parameters

This method has no parameters.

§Returns

Borrowed delay strategy used by the executor.

§Errors

This method does not return errors.

Source

pub fn jitter(&self) -> RetryJitter

Returns the jitter strategy.

§Parameters

This method has no parameters.

§Returns

Jitter strategy used by the executor.

§Errors

This method does not return errors.

Source

pub fn attempt_timeout(&self) -> Option<AttemptTimeoutOption>

Returns the optional per-attempt timeout settings.

§Parameters

This method has no parameters.

§Returns

Some(AttemptTimeoutOption) when per-attempt timeout is configured.

§Errors

This method does not return errors.

Source

pub fn worker_cancel_grace(&self) -> Duration

Returns the worker cancellation grace period.

§Parameters

This method has no parameters.

§Returns

Duration the worker-thread executor waits after requesting cooperative cancellation for a timed-out worker attempt.

Source

pub fn new( max_attempts: u32, max_operation_elapsed: Option<Duration>, max_total_elapsed: Option<Duration>, delay: RetryDelay, jitter: RetryJitter, ) -> Result<RetryOptions, 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_operation_elapsed: Optional cumulative user operation time budget for all attempts. Listener execution and retry sleeps are excluded.
  • max_total_elapsed: Optional monotonic elapsed-time budget for the whole retry flow. Operation execution, retry sleeps, retry-after sleeps, and retry control-path listener time are included.
  • 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 new_with_attempt_timeout( max_attempts: u32, max_operation_elapsed: Option<Duration>, max_total_elapsed: Option<Duration>, delay: RetryDelay, jitter: RetryJitter, attempt_timeout: Option<AttemptTimeoutOption>, ) -> Result<RetryOptions, RetryConfigError>

Creates and validates a retry option snapshot with attempt timeout.

§Parameters
  • max_attempts: Maximum number of attempts, including the first call. Must be greater than zero.
  • max_operation_elapsed: Optional cumulative user operation time budget for all attempts. Listener execution and retry sleeps are excluded.
  • max_total_elapsed: Optional monotonic elapsed-time budget for the whole retry flow. Operation execution, retry sleeps, retry-after sleeps, and retry control-path listener time are included.
  • delay: Base delay strategy used between attempts.
  • jitter: RetryJitter strategy applied to each base delay.
  • attempt_timeout: Optional per-attempt timeout settings.
§Returns

A validated RetryOptions value.

§Errors

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

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.

Source

pub fn base_delay_for_attempt(&self, attempt: u32) -> Duration

Calculates the base retry delay for one failed-attempt index.

§Parameters
  • attempt: Failed-attempt index, starting at 1.
§Returns

Base delay before jitter.

Source

pub fn delay_for_attempt(&self, attempt: u32) -> Duration

Calculates the retry delay for one failed-attempt index after jitter.

§Parameters
  • attempt: Failed-attempt index, starting at 1.
§Returns

Delay after jitter is applied.

Source

pub fn next_base_delay_from_current(&self, current: Duration) -> Duration

Calculates the next base delay from the current base delay.

For exponential delay, this advances by one multiplier step from current and caps at max. For other strategies, this delegates to the strategy’s per-attempt base behavior.

§Parameters
  • current: Current base delay before jitter.
§Returns

Next base delay before jitter.

Source

pub fn jittered_delay(&self, base_delay: Duration) -> Duration

Applies configured jitter to base_delay.

§Parameters
  • base_delay: Base delay before jitter.
§Returns

Delay after jitter.

Source

pub fn next_delay_from_current(&self, current: Duration) -> Duration

Calculates the next delay from the current base delay and applies jitter.

§Parameters
  • current: Current base delay before jitter.
§Returns

Next delay after jitter.

Trait Implementations§

Source§

impl Clone for RetryOptions

Source§

fn clone(&self) -> RetryOptions

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<(), Error>

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

impl Default for RetryOptions

Source§

fn default() -> RetryOptions

Creates the default retry options.

§Returns

Options with five attempts, no cumulative user operation time limit, exponential delay, no jitter, and the default worker cancellation grace.

§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 (const: unstable) · 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, D> IntoConfigDefault<T> for D
where D: IntoValueDefault<T>,

Source§

fn into_config_default(self) -> T

Converts this fallback value into T.
Source§

impl<T> IntoResult<T> for T

Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more