Skip to content

Commit

Permalink
rename crate to async-rate-limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
mindeng committed Aug 16, 2024
1 parent 218b996 commit 30b403e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "rate-limiter"
name = "async-rate-limiter"
version = "0.1.0"
edition = "2021"
license-file = "LICENSE"
description = "Implements a token bucket algorithm that can be used to limit API access frequency. Written in pure Rust."
homepage = "https://github.com/mindeng/rate-limiter-rs"
repository = "https://github.com/mindeng/rate-limiter-rs"
homepage = "https://github.com/mindeng/async-rate-limiter"
repository = "https://github.com/mindeng/async-rate-limiter"

[dependencies]
futures = "0.3.30"
Expand Down
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
# rate-limiter
# async-rate-limit

[![crates.io](https://img.shields.io/crates/v/rate-limiter.svg)](https://crates.io/crates/rate-limiter)
[![Documentation](https://docs.rs/rate-limiter/badge.svg)](https://docs.rs/rate-limiter)
[![crates.io](https://img.shields.io/crates/v/async-rate-limiter.svg)](https://crates.io/crates/async-rate-limiter)
[![Documentation](https://docs.rs/async-rate-limiter/badge.svg)](https://docs.rs/async-rate-limiter)
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![CI](https://github.com/mindeng/rate-limiter-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/mindeng/rate-limiter-rs/actions)
[![CI](https://github.com/mindeng/async-rate-limiter/actions/workflows/rust.yml/badge.svg)](https://github.com/mindeng/async-rate-limiter/actions)

rate-limiter implements a [token bucket
async-rate-limiter implements a [token bucket
algorithm](https://en.wikipedia.org/wiki/Token_bucket) that can be used to
limit API access frequency.

Thanks to Rust’s async capabilities, this feature is very simple to use. Just
put your operations after [`RateLimiter::acquire()`].`await`, then the
frequency control of the operations has been done.
# Example

Update your `Cargo.toml`:

```toml
[dependencies]
# Change features to ["rt-async-std"] if you are using async-std runtime.
async-rate-limiter = { version = "1.39.2", features = ["rt-tokio"] }
```

Thanks to Rust’s async functionality, this crate is very simple to use.
Just put your function call after [`RateLimiter::acquire()`].`await`, then
the function will be called with the specified rate limit.

Here is a simple example:

```rust
use rate_limiter::RateLimiter;
use async_rate_limiter::RateLimiter;
use std::time::Duration;

#[tokio::main]
Expand All @@ -26,14 +36,15 @@ async fn main() {
let ok = rl.acquire(None).await;
assert!(ok);
println!("Do something that you want to limit the rate ...");


// acquire with a timeout
let ok = rl.acquire(Some(Duration::from_secs(10))).await;
if ok {
println!("Do something that you want to limit the rate ...");
}
}

```

Please refer to
[![Documentation](https://docs.rs/rate-limiter/badge.svg)](https://docs.rs/rate-limiter)
for more details.
async-rate-limiter can support different async runtimes, tokio & async-std
are supported currently. You can use features to switch async runtimes.
26 changes: 20 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
//! rate-limiter implements a [token bucket
//! async-rate-limiter implements a [token bucket
//! algorithm](https://en.wikipedia.org/wiki/Token_bucket) that can be used to
//! limit API access frequency.
//!
//! Thanks to Rust’s async capabilities, this feature is very simple to use.
//! Just put your operations after [`RateLimiter::acquire()`].`await`, then the
//! frequency control of the operations has been done.
//! # Example
//!
//! Update your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! # Change features to ["rt-async-std"] if you are using async-std runtime.
//! async-rate-limiter = { version = "1.39.2", features = ["rt-tokio"] }
//! ```
//!
//! Thanks to Rust’s async functionality, this crate is very simple to use.
//! Just put your function call after [`RateLimiter::acquire()`].`await`, then
//! the function will be called with the specified rate limit.
//!
//! Here is a simple example:
//!
//! ```rust
//! use rate_limiter::RateLimiter;
//! use async_rate_limiter::RateLimiter;
//! use std::time::Duration;
//!
//! #[tokio::main]
Expand All @@ -19,14 +29,18 @@
//! let ok = rl.acquire(None).await;
//! assert!(ok);
//! println!("Do something that you want to limit the rate ...");
//!
//!
//! // acquire with a timeout
//! let ok = rl.acquire(Some(Duration::from_secs(10))).await;
//! if ok {
//! println!("Do something that you want to limit the rate ...");
//! }
//! }
//!
//! ```
//!
//! async-rate-limiter can support different async runtimes, tokio & async-std
//! are supported currently. You can use features to switch async runtimes.
mod token_bucket;
pub use token_bucket::TokenBucketRateLimiter as RateLimiter;
Expand Down

0 comments on commit 30b403e

Please sign in to comment.