pub trait Retryable<B: BackoffBuilder, T, E, Fut: Future<Output = Result<T, E>>, FutureFn: FnMut() -> Fut> {
// Required method
fn retry(self, builder: B) -> Retry<B::Backoff, T, E, Fut, FutureFn> ⓘ;
}
Expand description
Retryable will add retry support for functions that produce futures with results.
This means all types that implement FnMut() -> impl Future<Output = Result<T, E>>
will be able to use retry
.
For example:
- Functions without extra args:
ⓘ
async fn fetch() -> Result<String> {
Ok(reqwest::get("https://www.rust-lang.org").await?.text().await?)
}
- Closures
ⓘ
|| async {
let x = reqwest::get("https://www.rust-lang.org")
.await?
.text()
.await?;
Err(anyhow::anyhow!(x))
}