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: NonZeroU32Maximum attempts, including the initial attempt.
max_elapsed: Option<Duration>Maximum total elapsed time for the retry flow, in milliseconds.
delay: RetryDelayBase delay strategy between attempts.
jitter: RetryJitterRetryJitter applied to each base delay.
Implementations§
Source§impl RetryOptions
impl RetryOptions
Sourcepub const KEY_MAX_ATTEMPTS: &'static str = "max_attempts"
pub const KEY_MAX_ATTEMPTS: &'static str = "max_attempts"
Key for maximum attempts.
Sourcepub const KEY_MAX_ELAPSED_MILLIS: &'static str = "max_elapsed_millis"
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.
Sourcepub const KEY_DELAY_STRATEGY: &'static str = "delay_strategy"
pub const KEY_DELAY_STRATEGY: &'static str = "delay_strategy"
Backward-compatible alias for delay strategy name.
Sourcepub const KEY_FIXED_DELAY_MILLIS: &'static str = "fixed_delay_millis"
pub const KEY_FIXED_DELAY_MILLIS: &'static str = "fixed_delay_millis"
Key for fixed delay in milliseconds.
Sourcepub const KEY_RANDOM_MIN_DELAY_MILLIS: &'static str = "random_min_delay_millis"
pub const KEY_RANDOM_MIN_DELAY_MILLIS: &'static str = "random_min_delay_millis"
Key for random minimum delay in milliseconds.
Sourcepub const KEY_RANDOM_MAX_DELAY_MILLIS: &'static str = "random_max_delay_millis"
pub const KEY_RANDOM_MAX_DELAY_MILLIS: &'static str = "random_max_delay_millis"
Key for random maximum delay in milliseconds.
Sourcepub const KEY_EXPONENTIAL_INITIAL_DELAY_MILLIS: &'static str = "exponential_initial_delay_millis"
pub const KEY_EXPONENTIAL_INITIAL_DELAY_MILLIS: &'static str = "exponential_initial_delay_millis"
Key for exponential initial delay in milliseconds.
Sourcepub const KEY_EXPONENTIAL_MAX_DELAY_MILLIS: &'static str = "exponential_max_delay_millis"
pub const KEY_EXPONENTIAL_MAX_DELAY_MILLIS: &'static str = "exponential_max_delay_millis"
Key for exponential maximum delay in milliseconds.
Sourcepub const KEY_EXPONENTIAL_MULTIPLIER: &'static str = "exponential_multiplier"
pub const KEY_EXPONENTIAL_MULTIPLIER: &'static str = "exponential_multiplier"
Key for exponential multiplier.
Sourcepub const KEY_JITTER_FACTOR: &'static str = "jitter_factor"
pub const KEY_JITTER_FACTOR: &'static str = "jitter_factor"
Key for jitter factor.
Sourcepub fn new(
max_attempts: u32,
max_elapsed: Option<Duration>,
delay: RetryDelay,
jitter: RetryJitter,
) -> Result<Self, RetryConfigError>
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.
Sourcepub fn from_config<R>(config: &R) -> Result<Self, RetryConfigError>where
R: ConfigReader + ?Sized,
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.
Sourcepub fn validate(&self) -> Result<(), RetryConfigError>
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
impl Clone for RetryOptions
Source§fn clone(&self) -> RetryOptions
fn clone(&self) -> RetryOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RetryOptions
impl Debug for RetryOptions
Source§impl Default for RetryOptions
impl Default for RetryOptions
Source§fn default() -> Self
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.