pub struct RateLimitLayer { /* private fields */ }Expand description
Tower Layer that applies fixed-window rate limiting per client.
All service clones produced by this layer share the same in-memory counter store via an
std::sync::Arc, so the limit is enforced consistently across concurrent requests.
Apply with Axum’s .layer() call. Use RateLimitLayer::default() for 100 req/60 s
per X-Forwarded-For IP, or RateLimitLayer::new() to supply a custom
RateLimitConfig.
[!NOTE] Requests that carry no extractable key (header absent) pass through uncounted. The counter store grows with the number of unique client keys and is never evicted; for long-running servers with many unique IPs consider restarting periodically or using a shared external store.
§Examples
use axum::{routing::get, Router};
use rune_axum_ratelimit::RateLimitLayer;
let app: Router = Router::new()
.route("/api", get(|| async { "ok" }))
.layer(RateLimitLayer::default());Implementations§
Source§impl RateLimitLayer
impl RateLimitLayer
Sourcepub fn new(config: RateLimitConfig) -> RateLimitLayer
pub fn new(config: RateLimitConfig) -> RateLimitLayer
Creates a RateLimitLayer from a custom RateLimitConfig.
Trait Implementations§
Source§impl Clone for RateLimitLayer
impl Clone for RateLimitLayer
Source§fn clone(&self) -> RateLimitLayer
fn clone(&self) -> RateLimitLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateLimitLayer
impl Debug for RateLimitLayer
Source§impl Default for RateLimitLayer
impl Default for RateLimitLayer
Source§fn default() -> RateLimitLayer
fn default() -> RateLimitLayer
Returns the “default value” for a type. Read more
Source§impl<S> Layer<S> for RateLimitLayer
impl<S> Layer<S> for RateLimitLayer
Source§type Service = RateLimitService<S>
type Service = RateLimitService<S>
The wrapped service
Auto Trait Implementations§
impl !Freeze for RateLimitLayer
impl RefUnwindSafe for RateLimitLayer
impl Send for RateLimitLayer
impl Sync for RateLimitLayer
impl Unpin for RateLimitLayer
impl UnsafeUnpin for RateLimitLayer
impl UnwindSafe for RateLimitLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more