resilient-rs 0.1.1

A Rust utility library for fault tolerance, including retry strategies, backoff mechanisms, and failure handling.
Documentation

A Rust utility library for fault tolerance, including retry strategies, backoff mechanisms, failure handling and much more. Crates.io Downloads YouTube πŸ’– Loved the work? Subscribe to my YouTube channel or consider giving this repository a ⭐ to show your support!

Features

Type Feature Status
Synchronous Retry βœ… Stable
Synchronous Retry-with-backoff 🚧 Under Development
Asynchronous Retry βœ… Stable
Asynchronous Retry-with-backoff 🚧 Under Development
Asynchronous Circuit Breaker πŸ› οΈ Planned
Synchronous/Asynchronous More Examples πŸ› οΈ Planned

πŸ“¦ 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.1.0" # 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::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 log::{info, warn};

async fn example_operation() -> Result<&'static str, &'static str> {
  static mut ATTEMPTS: usize = 0;
  unsafe {
    ATTEMPTS += 1;
    if ATTEMPTS == 3 {
      Ok("Success")
    } else {
      Err("Failure")
    }
  }
}

#[tokio::main]
async fn main() {
  use resilient_rs::asynchronous::retry::retry;
  use resilient_rs::config::RetryConfig;

  let retry_config = RetryConfig {
    max_attempts: 5,
    delay: Duration::from_secs(1),
  };

  let result = retry(example_operation, &retry_config).await;
  match result {
    Ok(output) => println!("Operation succeeded: {}", output),
    Err(err) => println!("Operation failed: {}", err),
  }
}

πŸš€ Contributing Guidelines

We welcome contributions to this project! Please follow these steps to contribute:

πŸ› For Issues

  • If you find an issue you'd like to work on, please comment on the issue and tag me (@semicolon-10) to assign it to you.
    πŸ’‘ Tip: Make sure the issue is not already assigned to someone else!
  • Once assigned, you can start working on the issue. πŸŽ‰

🌟 For Planned Features

  • If you'd like to work on a feature listed in the "Planned" section of the README, first create a new issue for that feature.
    πŸ“ Note: Clearly describe your approach or any details about how you plan to implement the feature.
  • Tag me (@semicolon-10) in the issue and request assignment. πŸ™‹β€β™‚οΈ

πŸ”§ Submitting Your Work

  1. 🍴 Fork the repository and create a new branch for your work.
  2. πŸ› οΈ Make your changes and ensure they are well-tested.
  3. βœ… Make sure all pipelines pass successfully before tagging me for review.
  4. πŸ“€ Submit a pull request (PR) with a clear description of the changes you made.
  5. πŸ”— Link the issue you worked on in the PR description.

🀝 Code of Conduct

  • Be respectful and collaborative when interacting with other contributors. πŸ€—
  • Ensure your code follows the project's coding standards and guidelines. βœ…

πŸ› οΈ Example Workflow

  1. πŸ” Find an issue or planned feature you'd like to work on.
  2. πŸ’¬ Comment on the issue or create a new issue for the planned feature.
  3. πŸ™‹ Tag me (@semicolon-10) to assign the issue to you.
  4. πŸ–ŠοΈ Work on the issue in your forked repository and submit a pull request.