A library which provides macros that automatically re-execute both synchronous and asynchronous (tokio with sleep) functions upon failure.
Here are two simple examples using both the synchronous and asynchronous macros.
```rust use retrymacro::{retry, retrysleep, RetryError};
fn can_fail(input: &str) -> Result
fn main() { // Retry the canfail function 5 times with the input "notanumber" let res = retry!(5, canfail, "notanumber"); assert!(res.iserr()); asserteq!(res.unwrap_err().retries.len(), 5);
// Retry the can_fail function 5 times with the input "not_a_number", sleep for 100 milliseconds between retries
let res = retry_sleep!(5, 100, can_fail, "not_a_number");
assert!(res.is_err());
assert_eq!(res.unwrap_err().retries.len(), 5);
} ```
```rust use retrymacro::{retryasync, retryasyncsleep, RetryError};
async fn canfailasync(input: &str) -> Result
async fn main() { // Retry the canfail function 5 times with the input "notanumber" let res = retryasync!(5, canfailasync, "notanumber"); assert!(res.iserr()); asserteq!(res.unwrap_err().retries.len(), 5);
// Retry the can_fail function 5 times with the input "not_a_number", sleep for 100 milliseconds between retries
let res = retry_async_sleep!(5, 100, can_fail_async, "not_a_number");
assert!(res.is_err());
assert_eq!(res.unwrap_err().retries.len(), 5);
} ```
retry_macro
is distributed under the MIT and Apache-2.0 licenses.