Skip to content

Commit

Permalink
Bump to version 0.1.0 (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Sep 7, 2022
1 parent d0317cf commit 37443a3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
4 changes: 0 additions & 4 deletions .github/actions/check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
//! }
//! ```

#![deny(missing_docs)]
#![deny(unused_qualifications)]

mod backoff;
pub use backoff::Backoff;

Expand Down
32 changes: 11 additions & 21 deletions src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output = std::result::Result<T, E>>`
/// That means all types that implement `FnMut() -> impl Future<Output = Result<T, E>>`
/// will be able to use `retry`.
///
/// For example:
Expand Down Expand Up @@ -54,36 +54,26 @@ use crate::Backoff;
/// Ok(())
/// }
/// ```
pub trait Retryable<
B: Backoff,
T,
E,
Fut: Future<Output = std::result::Result<T, E>>,
FutureFn: FnMut() -> Fut,
>
pub trait Retryable<B: Backoff, T, E, Fut: Future<Output = Result<T, E>>, FutureFn: FnMut() -> Fut>
{
/// Generate a new retry
fn retry(self, backoff: B) -> Retry<B, T, E, Fut, FutureFn>;
}

impl<B, T, E, Fut, FutureFn> Retryable<B, T, E, Fut, FutureFn> for FutureFn
where
B: Backoff,
Fut: Future<Output = std::result::Result<T, E>>,
Fut: Future<Output = Result<T, E>>,
FutureFn: FnMut() -> Fut,
{
fn retry(self, backoff: B) -> Retry<B, T, E, Fut, FutureFn> {
Retry::new(self, backoff)
}
}

/// Retry struct generated by [`Retryable`].
#[pin_project]
pub struct Retry<
B: Backoff,
T,
E,
Fut: Future<Output = std::result::Result<T, E>>,
FutureFn: FnMut() -> Fut,
> {
pub struct Retry<B: Backoff, T, E, Fut: Future<Output = Result<T, E>>, FutureFn: FnMut() -> Fut> {
backoff: B,
retryable: fn(&E) -> bool,
future_fn: FutureFn,
Expand All @@ -95,7 +85,7 @@ pub struct Retry<
impl<B, T, E, Fut, FutureFn> Retry<B, T, E, Fut, FutureFn>
where
B: Backoff,
Fut: Future<Output = std::result::Result<T, E>>,
Fut: Future<Output = Result<T, E>>,
FutureFn: FnMut() -> Fut,
{
/// Create a new retry.
Expand Down Expand Up @@ -198,7 +188,7 @@ where
/// `tokio::time::Sleep` is a very struct that occupy 640B, so we wrap it
/// into a `Pin<Box<_>>` to avoid this enum too large.
#[pin_project(project = StateProject)]
enum State<T, E, Fut: Future<Output = std::result::Result<T, E>>> {
enum State<T, E, Fut: Future<Output = Result<T, E>>> {
Idle,
Polling(#[pin] Fut),
// TODO: we need to support other sleeper
Expand All @@ -207,7 +197,7 @@ enum State<T, E, Fut: Future<Output = std::result::Result<T, E>>> {

impl<T, E, Fut> Default for State<T, E, Fut>
where
Fut: Future<Output = std::result::Result<T, E>>,
Fut: Future<Output = Result<T, E>>,
{
fn default() -> Self {
State::Idle
Expand All @@ -217,10 +207,10 @@ where
impl<B, T, E, Fut, FutureFn> Future for Retry<B, T, E, Fut, FutureFn>
where
B: Backoff,
Fut: Future<Output = std::result::Result<T, E>>,
Fut: Future<Output = Result<T, E>>,
FutureFn: FnMut() -> Fut,
{
type Output = std::result::Result<T, E>;
type Output = Result<T, E>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let mut this = self.project();
Expand Down

0 comments on commit 37443a3

Please sign in to comment.