backoff_macro
backoff_macro is a Rust procedural macro that adds retry logic with exponential backoff to asynchronous functions. This crate leverages the backoff crate to handle retries and allows users to simply annotate their functions with #[backoff] to enable this functionality.
Features
- Automatically retries asynchronous functions on failure.
- Uses exponential backoff to space out retries.
- Simple and easy-to-use attribute macro.
Installation
Add backoff_macro to your Cargo.toml:
[]
= "0.1.0"
= "0.3.0"
= { = "1", = ["full"] }
Usage
To use the #[backoff] macro, simply annotate your asynchronous function with #[backoff]. The function should return a Result<T, E> type, where E implements the From<E> trait for backoff::Error<E>.
Example
Here's a basic example demonstrating how to use the #[backoff] macro:
use backoff;
use ;
use Arc;
use Error;
use main;
async
async
Explanation
- Annotation: Use
#[backoff]to annotate the asynchronous function you want to apply retry logic to. - Retry Logic: The macro will wrap the function body with retry logic using the
backoff::future::retrymethod. - Return Type: Ensure the function returns a
Result<T, E>type.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.