Expand description
relentless — a Rust library for retrying fallible operations and polling for conditions.
This crate provides composable retry strategies with support for std, alloc,
and no_std environments.
§Custom wait strategies
use core::time::Duration;
use relentless::{RetryState, Wait, wait};
struct CustomWait(Duration);
impl Wait for CustomWait {
fn next_wait(&self, _state: &RetryState) -> Duration {
self.0
}
}
let strategy = CustomWait(Duration::from_millis(20))
.cap(Duration::from_millis(15))
.chain(wait::fixed(Duration::from_millis(50)), 2);
let state = RetryState::new(3, None);
assert_eq!(strategy.next_wait(&state), Duration::from_millis(50));§Extension-first usage
In sync std builds, .sleep(...) is optional because relentless falls
back to std::thread::sleep. The example below still calls .sleep(...)
so it compiles under no_std documentation test runs too.
use core::time::Duration;
use relentless::{RetryExt, stop, wait};
let result = (|| Err::<u32, &str>("transient"))
.retry()
.stop(stop::attempts(3))
.wait(wait::fixed(Duration::from_millis(5)))
.sleep(|_dur| {})
.call();
assert!(result.is_err());Re-exports§
Modules§
- predicate
- Predicate trait and built-in retry predicate factories.
- sleep
- stop
- Stop trait and built-in stop strategies.
- wait
- Wait trait and built-in wait strategies.
Structs§
- Async
Retry - Async retry execution object.
- Async
Retry Builder - Owned async retry builder created from
AsyncRetryExt::retry_async. - Async
Retry Builder With Stats - Owned async retry builder wrapper that returns statistics.
- Async
Retry With Stats - Async retry execution wrapper that returns statistics.
- Attempt
State - Read-only context passed to the
after_attempthook. - Exit
State - Final read-only context passed to the
on_exithook. - Retry
Policy - Reusable retry configuration.
- Retry
State - Non-generic retry context passed to
Stop::should_stop,Wait::next_wait, the operation, and thebefore_attempthook. - Retry
Stats - Aggregate statistics for a completed retry execution.
- Sync
Retry - Sync retry execution object.
- Sync
Retry Builder - Owned sync retry builder created from
RetryExt::retry. - Sync
Retry Builder With Stats - Owned sync retry builder wrapper that returns statistics.
- Sync
Retry With Stats - Sync retry execution wrapper that returns statistics.
Enums§
- Retry
Error - Error returned when a retry loop terminates without producing an accepted result.
- Stop
Reason - Why a retry loop terminated.
Traits§
- Async
Retry Ext - Extension trait to start async retries directly from a closure/function.
- Retry
Ext - Extension trait to start sync retries directly from a closure/function.
Functions§
- retry
- Returns a
SyncRetryBuilderwith default policy:attempts(3),exponential(100ms),any_error(). - retry_
async - Returns an
AsyncRetryBuilderwith default policy:attempts(3),exponential(100ms),any_error().
Type Aliases§
- Default
Async Retry Builder - Alias for the default owned async retry builder returned by
AsyncRetryExt::retry_async. - Default
Async Retry Builder With Stats - Alias for the default owned async retry builder-with-stats returned by
calling
.with_stats()onAsyncRetryExt::retry_async. - Default
Sync Retry Builder - Alias for the default owned sync retry builder returned by
RetryExt::retry. - Default
Sync Retry Builder With Stats - Alias for the default owned sync retry builder-with-stats returned by
calling
.with_stats()onRetryExt::retry. - Retry
Result - Convenience alias:
Result<T, RetryError<T, E>>.