pub struct RetryPolicy { /* private fields */ }Expand description
Configuration for automatic retry behavior on concurrency conflicts.
RetryPolicy allows library consumers to customize how execute() handles version conflicts during command execution. Uses method chaining for ergonomic configuration.
§Examples
// Custom retry policy with 2 retries (3 total attempts) instead of default 4 retries
let policy = RetryPolicy::new().max_retries(2);
// Custom retry policy with fixed backoff
let policy = RetryPolicy::new()
.max_retries(2)
.backoff_strategy(BackoffStrategy::Fixed {
delay_ms: DelayMilliseconds::new(50),
});Implementations§
Source§impl RetryPolicy
impl RetryPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new RetryPolicy with default values.
Default configuration matches I-002 hardcoded values:
- max_retries: 4 (5 total attempts including initial)
- backoff_strategy: Exponential with 10ms base
- jitter: ±20% (applied during execution)
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Configure the maximum number of retry attempts.
Returns self for method chaining.
§Examples
let policy = RetryPolicy::new().max_retries(2);Sourcepub fn backoff_strategy(self, strategy: BackoffStrategy) -> Self
pub fn backoff_strategy(self, strategy: BackoffStrategy) -> Self
Configure the backoff strategy for retry delays.
Returns self for method chaining.
§Examples
let policy = RetryPolicy::new()
.backoff_strategy(BackoffStrategy::Fixed {
delay_ms: DelayMilliseconds::new(50),
});Sourcepub fn with_metrics_hook<H: MetricsHook + 'static>(self, hook: H) -> Self
pub fn with_metrics_hook<H: MetricsHook + 'static>(self, hook: H) -> Self
Configure a metrics hook for retry lifecycle events.
The hook will receive callbacks on each retry attempt with structured context data for metrics collection systems.
Returns self for method chaining.
§Examples
ⓘ
struct MyMetricsHook;
impl MetricsHook for MyMetricsHook {
fn on_retry_attempt(&self, ctx: &RetryContext) {
// Record metrics
}
}
let policy = RetryPolicy::new()
.with_metrics_hook(MyMetricsHook);Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RetryPolicy
impl !RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl !UnwindSafe for RetryPolicy
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