8 unstable releases (3 breaking)
new 0.4.2 | Mar 6, 2025 |
---|---|
0.4.1 | Mar 5, 2025 |
0.3.0 | Mar 1, 2025 |
0.2.1 | Mar 1, 2025 |
0.1.1 | Feb 28, 2025 |
#194 in Concurrency
410 downloads per month
39KB
623 lines
Resilient-rs
A Rust utility library for fault tolerance, including retry strategies, backoff mechanisms, failure handling and much more.
π Loved the work? Subscribe to my YouTube channel or consider giving this repository a β to show your support!
Feature Overview
Feature | Details | Status |
---|---|---|
Retry | Basic retry functionality | β Stable |
With Backoff (exponential) | β Stable | |
With Fallback | β Stable | |
Circuit Breaker | Prevents cascading failures | π οΈ Planned |
Logging | Comprehensive debugging support | β Stable |
More Examples | Additional usage examples | π οΈ Planned |
Notes:
- Supported Contexts: All features are available for both synchronous and asynchronous operations.
π¦ How to Use resilient-rs
Hereβs a quick example of how to use the resilient-rs
crate in your Rust project.
1οΈβ£ Add resilient-rs
to Your Cargo.toml
Add the following line to your Cargo.toml
file:
[dependencies]
resilient-rs = "0.4.2" # Replace with the latest version
OR
cargo add resilient-rs
Synchronous
use std::time::Duration;
use resilient_rs::config::RetryConfig;
use resilient_rs::synchronous::retry;
fn main() {
let retry_config = RetryConfig::default();
let result: Result<i32, &str> = retry(|| {
Err("Temporary failure")
}, &retry_config);
assert!(result.is_err());
}
Asynchronous
use tokio::time::Duration;
use reqwest::Client;
use resilient_rs::asynchronous::retry;
use resilient_rs::config::RetryConfig;
async fn fetch_url() -> Result<String, reqwest::Error> {
let client = Client::new();
let response = client.get("https://example.com")
.send()
.await?;
if response.status().is_success() {
response.text().await
} else {
Err(reqwest::Error::new(reqwest::StatusCode::from_u16(response.status().as_u16()).unwrap(), "Request failed"))
}
}
#[tokio::main]
async fn main() {
let retry_config = RetryConfig::default();
let result = retry(fetch_url, &retry_config).await;
match result {
Ok(output) => println!("Operation succeeded: {}", output),
Err(err) => println!("Operation failed: {}", err),
}
}
π Contributing Guidelines
We welcome your contributions! Here's how to get started:
π Issues & π Features
- Find an issue or planned feature you'd like to work on.
- Comment on the issue (or create one for planned features) and tag me (
@semicolon-10
) for assignment.
π‘ Tip: Ensure it's not already assigned! - Once assigned, start working. π
π§ Submitting Work
- π΄ Fork the repo and create a new branch.
- π οΈ Make changes and test thoroughly.
- β Ensure git actions pass before tagging me for review.
- π€ Submit a PR with a clear description and link the issue.
π€ Code of Conduct
- Be respectful and collaborative. π€
- Follow coding standards and guidelines. β
Dependencies
~5β13MB
~183K SLoC