From 37443a3141e3ebc2bc4891813d431c0bf4ee5df8 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 7 Sep 2022 12:35:16 +0800 Subject: [PATCH] Bump to version 0.1.0 (#16) Signed-off-by: Xuanwo Signed-off-by: Xuanwo --- .github/actions/check/action.yml | 4 ---- Cargo.toml | 16 ++++++++-------- src/lib.rs | 3 +++ src/retry.rs | 32 +++++++++++--------------------- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/.github/actions/check/action.yml b/.github/actions/check/action.yml index 4e1d0ae..dc35f38 100644 --- a/.github/actions/check/action.yml +++ b/.github/actions/check/action.yml @@ -7,10 +7,6 @@ inputs: runs: using: "composite" steps: - - uses: Swatinem/rust-cache@v1 - with: - sharedKey: base-v1 - - name: Format uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index bc3230c..dd8054e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,15 +5,15 @@ documentation = "https://docs.rs/backon" edition = "2021" license = "Apache-2.0" name = "backon" -version = "0.0.2" +version = "0.1.0" [dependencies] -futures = "0.3.21" -pin-project = "1.0.10" -rand = "0.8.5" -tokio = { version = "1.17.0", features = ["time"] } +futures = "0.3" +pin-project = "1" +rand = "0.8" +tokio = { version = "1", features = ["time"] } [dev-dependencies] -anyhow = "1.0.56" -reqwest = "0.11.10" -tokio = { version = "1.17.0", features = ["full"] } +anyhow = "1" +reqwest = "0.11" +tokio = { version = "1", features = ["full"] } diff --git a/src/lib.rs b/src/lib.rs index 291e302..4f8703f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,6 +57,9 @@ //! } //! ``` +#![deny(missing_docs)] +#![deny(unused_qualifications)] + mod backoff; pub use backoff::Backoff; diff --git a/src/retry.rs b/src/retry.rs index c7e6525..eeb712d 100644 --- a/src/retry.rs +++ b/src/retry.rs @@ -9,7 +9,7 @@ use crate::Backoff; /// Retryable will add retry support for functions that produces a futures with results. /// -/// That means all types that implement `FnMut() -> impl Future>` +/// That means all types that implement `FnMut() -> impl Future>` /// will be able to use `retry`. /// /// For example: @@ -54,21 +54,16 @@ use crate::Backoff; /// Ok(()) /// } /// ``` -pub trait Retryable< - B: Backoff, - T, - E, - Fut: Future>, - FutureFn: FnMut() -> Fut, -> +pub trait Retryable>, FutureFn: FnMut() -> Fut> { + /// Generate a new retry fn retry(self, backoff: B) -> Retry; } impl Retryable for FutureFn where B: Backoff, - Fut: Future>, + Fut: Future>, FutureFn: FnMut() -> Fut, { fn retry(self, backoff: B) -> Retry { @@ -76,14 +71,9 @@ where } } +/// Retry struct generated by [`Retryable`]. #[pin_project] -pub struct Retry< - B: Backoff, - T, - E, - Fut: Future>, - FutureFn: FnMut() -> Fut, -> { +pub struct Retry>, FutureFn: FnMut() -> Fut> { backoff: B, retryable: fn(&E) -> bool, future_fn: FutureFn, @@ -95,7 +85,7 @@ pub struct Retry< impl Retry where B: Backoff, - Fut: Future>, + Fut: Future>, FutureFn: FnMut() -> Fut, { /// Create a new retry. @@ -198,7 +188,7 @@ where /// `tokio::time::Sleep` is a very struct that occupy 640B, so we wrap it /// into a `Pin>` to avoid this enum too large. #[pin_project(project = StateProject)] -enum State>> { +enum State>> { Idle, Polling(#[pin] Fut), // TODO: we need to support other sleeper @@ -207,7 +197,7 @@ enum State>> { impl Default for State where - Fut: Future>, + Fut: Future>, { fn default() -> Self { State::Idle @@ -217,10 +207,10 @@ where impl Future for Retry where B: Backoff, - Fut: Future>, + Fut: Future>, FutureFn: FnMut() -> Fut, { - type Output = std::result::Result; + type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut this = self.project();