pub struct RetryConfig {
pub max_retries: u32,
pub initial_delay: Duration,
pub max_delay: Duration,
pub backoff_multiplier: f64,
pub jitter: bool,
}Expand description
Configuration for automatic retry with exponential backoff.
Applied to retryable errors (RateLimit, Timeout, Http).
Attach it to a client with
ClientBuilder::retry_config or to a
single request with
RequestBuilder::retry_config.
§Examples
use std::time::Duration;
use rai_sdk::RetryConfig;
// Default: 3 retries, 1s initial delay, 2x backoff, jitter enabled
let config = RetryConfig::default();
// Custom: 5 retries, 500ms initial delay, no jitter
let custom = RetryConfig::new()
.with_max_retries(5)
.with_initial_delay(Duration::from_millis(500))
.with_jitter(false);
// Disable retries entirely
let none = RetryConfig::none();Fields§
§max_retries: u32Maximum number of retry attempts (0 = no retries).
initial_delay: DurationDelay before the first retry.
max_delay: DurationMaximum delay between retries (caps exponential growth).
backoff_multiplier: f64Multiplier applied to the delay after each attempt.
jitter: boolAdd random jitter to avoid thundering herd.
Implementations§
Source§impl RetryConfig
impl RetryConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a default retry configuration (3 retries, 1s initial delay, 2x backoff).
Sourcepub fn with_max_retries(self, n: u32) -> Self
pub fn with_max_retries(self, n: u32) -> Self
Set the maximum number of retry attempts.
Sourcepub fn with_initial_delay(self, delay: Duration) -> Self
pub fn with_initial_delay(self, delay: Duration) -> Self
Set the initial delay before the first retry.
Sourcepub fn with_max_delay(self, delay: Duration) -> Self
pub fn with_max_delay(self, delay: Duration) -> Self
Set the maximum delay between retries.
Sourcepub fn with_backoff_multiplier(self, multiplier: f64) -> Self
pub fn with_backoff_multiplier(self, multiplier: f64) -> Self
Set the backoff multiplier.
Sourcepub fn with_jitter(self, jitter: bool) -> Self
pub fn with_jitter(self, jitter: bool) -> Self
Enable or disable jitter.
Trait Implementations§
Source§impl Clone for RetryConfig
impl Clone for RetryConfig
Source§fn clone(&self) -> RetryConfig
fn clone(&self) -> RetryConfig
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryConfig
impl Debug for RetryConfig
Source§impl Default for RetryConfig
impl Default for RetryConfig
Source§impl<'de> Deserialize<'de> for RetryConfig
impl<'de> Deserialize<'de> for RetryConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RetryConfig
impl RefUnwindSafe for RetryConfig
impl Send for RetryConfig
impl Sync for RetryConfig
impl Unpin for RetryConfig
impl UnsafeUnpin for RetryConfig
impl UnwindSafe for RetryConfig
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
Mutably borrows from an owned value. Read more