pub struct RateLimiter { /* private fields */ }Expand description
Token bucket rate limiter implementation
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(capacity: u32, refill_per_second: u32) -> Self
pub fn new(capacity: u32, refill_per_second: u32) -> Self
Create a new rate limiter with specified capacity and refill rate
Sourcepub fn try_acquire(&self, tokens: u32) -> bool
pub fn try_acquire(&self, tokens: u32) -> bool
Try to acquire tokens, returns true if successful
Sourcepub fn last_accessed(&self) -> Instant
pub fn last_accessed(&self) -> Instant
Get the time of last activity (used for cleanup of idle limiters)
Trait Implementations§
Auto 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