A lightweight, zero-dependency Rust library for retrying fallible operations with flexible delay and backoff strategies.
Features
- Zero External Dependencies: Fast compile times and zero bloat.
- Builder Pattern: Clean, chainable API for configuring retry behaviors.
- Exponential Backoff: Easily configure delay scaling factors for resilient network/IO operations.
- Zero-Cost Abstractions: Lightweight implementation designed for maximum performance.
- 100% Safe & Tested: Fully covered with unit tests and doc tests.
Installation
Add quick_retry to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Basic Usage
Retry an operation up to 3 times with a default 100ms fixed delay:
use Retry;
use Duration;
Advanced Usage: Exponential Backoff
increase delay exponential after each failed attempt (e.g 100ms --> 200ms --> 400ms):
use Retry;
use Duration;
API Reference
| Method | Dercription | Default |
|---|---|---|
Retry::new() |
Creates Retry build instance. |
max_attempts: 3, delay: 100ms , Fixed |
.max_attempts(u32) |
Sets the maximum number of attempts before failing. | 3 |
.delay(Duration) |
Sets the initial delay duration between | 100ms |
exponential_backoff(f64) |
Enables exponential backoff with th given multiplier factor. | Disabled(Fixed) |
.run(F) |
Executes the operation closure FnMut() -> Result<T,E>. |
N/A |
License
This project Licensed under the MIT License-see the LICENSE file for details.
Support & Feadback
if you find this crate useful, please consider given it a star on GitHub