pub struct RateLimiter { /* private fields */ }Expand description
Thread-safe rate limiter using GCRA algorithm
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: RateLimiterConfig) -> Self
pub fn new(config: RateLimiterConfig) -> Self
Create a new rate limiter with the given configuration
Sourcepub fn default_limiter() -> Self
pub fn default_limiter() -> Self
Create rate limiter with defaults (100 req/s, burst of 10)
Sourcepub fn check(&self) -> Result<(), f64>
pub fn check(&self) -> Result<(), f64>
Check if a request is allowed
Returns Ok(()) if allowed, Err(retry_after_secs) if rate limited
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Get current capacity remaining (approximate)
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§fn clone(&self) -> RateLimiter
fn clone(&self) -> RateLimiter
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 moreAuto Trait Implementations§
impl Freeze for RateLimiter
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnwindSafe for RateLimiter
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