pub struct RateLimitBuilder { /* private fields */ }Expand description
Builder for configuring a RateLimitMiddleware.
Implementations§
Source§impl RateLimitBuilder
impl RateLimitBuilder
Sourcepub fn route<F>(self, configure: F) -> Self
pub fn route<F>(self, configure: F) -> Self
Add a route using a closure-based configuration.
§Panics
Panics if no limits are configured via .limit().
§Example
use route_ratelimit::RateLimitMiddleware;
use std::time::Duration;
let middleware = RateLimitMiddleware::builder()
.route(|r| r.limit(15000, Duration::from_secs(10)))
.route(|r| r.path("/api").limit(1000, Duration::from_secs(10)))
.build();Sourcepub fn host<F>(self, host: impl Into<String>, configure: F) -> Self
pub fn host<F>(self, host: impl Into<String>, configure: F) -> Self
Configure routes for a specific host using a scoped builder.
This is the preferred way to configure multiple routes for the same host, as it avoids repeating the host for each route.
§Example
use route_ratelimit::{RateLimitMiddleware, ThrottleBehavior};
use std::time::Duration;
use http::Method;
let middleware = RateLimitMiddleware::builder()
.host("clob.polymarket.com", |host| {
host
.route(|r| r.limit(9000, Duration::from_secs(10)))
.route(|r| r.path("/book").limit(1500, Duration::from_secs(10)))
.route(|r| r.path("/price").limit(1500, Duration::from_secs(10)))
.route(|r| {
r.method(Method::POST)
.path("/order")
.limit(3500, Duration::from_secs(10))
.limit(36000, Duration::from_secs(600))
})
})
.host("data-api.polymarket.com", |host| {
host
.route(|r| r.limit(1000, Duration::from_secs(10)))
.route(|r| r.path("/trades").limit(200, Duration::from_secs(10)))
})
.build();Sourcepub fn build(self) -> RateLimitMiddleware
pub fn build(self) -> RateLimitMiddleware
Build the middleware.
§Warnings
If the tracing feature is enabled, this method will emit a warning
when catch-all routes (routes with no host, method, or path filters)
are followed by more specific routes. This pattern may cause unexpected
behavior since all matching routes’ limits are applied.
Trait Implementations§
Source§impl Clone for RateLimitBuilder
impl Clone for RateLimitBuilder
Source§fn clone(&self) -> RateLimitBuilder
fn clone(&self) -> RateLimitBuilder
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 RateLimitBuilder
impl Debug for RateLimitBuilder
Source§impl Default for RateLimitBuilder
impl Default for RateLimitBuilder
Source§fn default() -> RateLimitBuilder
fn default() -> RateLimitBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RateLimitBuilder
impl RefUnwindSafe for RateLimitBuilder
impl Send for RateLimitBuilder
impl Sync for RateLimitBuilder
impl Unpin for RateLimitBuilder
impl UnwindSafe for RateLimitBuilder
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