pub struct RetryLayer { /* private fields */ }Expand description
A Tower layer that adds retry logic with exponential backoff to RPC requests.
This layer wraps each RPC request and automatically retries on transient failures using exponential backoff. The backoff formula is:
delay = min(base_delay * 2^attempt, max_delay)§Example
ⓘ
use semioscan::transport::RetryLayer;
use alloy_rpc_client::ClientBuilder;
use std::time::Duration;
// Retry up to 3 times with exponential backoff
let layer = RetryLayer::new();
// Or with custom configuration
let layer = RetryLayer::builder()
.max_retries(5)
.base_delay(Duration::from_millis(200))
.max_delay(Duration::from_secs(60))
.build();
let client = ClientBuilder::default()
.layer(layer)
.http(rpc_url);Implementations§
Source§impl RetryLayer
impl RetryLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new retry layer with default settings.
Default settings:
- 3 retry attempts
- 100ms base delay
- 30s maximum delay
§Example
use semioscan::transport::RetryLayer;
let layer = RetryLayer::new();Sourcepub fn builder() -> RetryLayerBuilder
pub fn builder() -> RetryLayerBuilder
Creates a builder for customizing retry configuration.
§Example
use semioscan::transport::RetryLayer;
use std::time::Duration;
let layer = RetryLayer::builder()
.max_retries(5)
.base_delay(Duration::from_millis(200))
.build();Sourcepub fn with_max_retries(max_retries: u32) -> Self
pub fn with_max_retries(max_retries: u32) -> Self
Creates a retry layer with a specific number of retries.
Uses default base and max delays.
§Example
use semioscan::transport::RetryLayer;
// Retry up to 5 times
let layer = RetryLayer::with_max_retries(5);Sourcepub fn aggressive() -> Self
pub fn aggressive() -> Self
Creates a retry layer with aggressive retry settings.
This preset uses:
- 5 retry attempts
- 50ms base delay
- 10s maximum delay
Suitable for high-availability scenarios where quick retries are needed.
§Example
use semioscan::transport::RetryLayer;
let layer = RetryLayer::aggressive();Sourcepub fn conservative() -> Self
pub fn conservative() -> Self
Creates a retry layer with conservative retry settings.
This preset uses:
- 3 retry attempts
- 500ms base delay
- 60s maximum delay
Suitable for scenarios where RPC endpoints may need time to recover.
§Example
use semioscan::transport::RetryLayer;
let layer = RetryLayer::conservative();Trait Implementations§
Source§impl Clone for RetryLayer
impl Clone for RetryLayer
Source§fn clone(&self) -> RetryLayer
fn clone(&self) -> RetryLayer
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 moreSource§impl Debug for RetryLayer
impl Debug for RetryLayer
Source§impl Default for RetryLayer
impl Default for RetryLayer
Auto Trait Implementations§
impl Freeze for RetryLayer
impl RefUnwindSafe for RetryLayer
impl Send for RetryLayer
impl Sync for RetryLayer
impl Unpin for RetryLayer
impl UnwindSafe for RetryLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more