Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Rust
name: Pull Request

on:
pull_request:
types:
- opened
- synchronize
paths:
- Cargo.toml
- '**/Cargo.toml'
Expand Down Expand Up @@ -35,6 +36,8 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: rust-toolchain-cache
- name: Version Check
run: cargo fmt --version
- name: Enforce formatting
run: cargo fmt --check

Expand All @@ -49,7 +52,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
key: rust-toolchain-cache
- name: Linting
- name: Version Check
run: cargo clippy --version
- name: Linting
run: cargo clippy --all-targets -- -D warnings
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# - id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: clippy
args: [ --all-targets, --, -D, clippy::all ]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ A flexible retry library for Rust async operations with configurable backoff str
- `tokio` (via `tokio` feature)
- `async-std` (via `async-std` feature)

## Contributing

Formatting and linting hooks are run via `pre-commit` and will run prior to each commit. If the hooks fail they will reject the commit. The `end-of-file-fixer` and `trailing-whitespace` will automatically make the necessary fixes and you can just `git add ... && git commit -m ...` again immediately. The `fmt` and `clippy` lints will require your intervention.

If you _MUST_ bypass the commit hooks to get things on a branch you can `git commit --no-verify -m ...` to skip the hooks.

```
brew install pre-commit
pre-commit install
```

```yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# - id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: fmt
- id: clippy
args: [ --all-targets, --, -D, clippy::all ]
```
## Quick Start
```rust
Expand Down
17 changes: 14 additions & 3 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ async fn main() {
.stop_after(10)
.full_jitter()
.fixed(Duration::from_millis(200))
.on_retry(|res, attempt| { println!("[retry] start to call retry(): attempt = {}, prev = {:?}", attempt, res) })
.on_retry(|res, attempt| {
println!(
"[retry] start to call retry(): attempt = {}, prev = {:?}",
attempt, res
)
})
.retry(|| async { this_errors("[retry] running").await })
.await
});
Expand All @@ -44,8 +49,14 @@ async fn main() {
.stop_after(3)
.full_jitter()
.fixed(Duration::from_millis(200))
.on_retry(|res, attempt| { println!("[on_retry] start to call retry() again. In last attempt = {}, result = {:?}", attempt, res) })
.on_retry(|res, attempt| {
println!(
"[on_retry] start to call retry() again. In last attempt = {}, result = {:?}",
attempt, res
)
})
.retry(|| async { this_errors("[retry] call `.retry()` and failed").await })
.await
}).await;
})
.await;
}
Loading