#[repr(align(64))]pub struct ApiRateLimiter { /* private fields */ }
Expand description
API rate limiter (requests per second)
Implementations§
Source§impl ApiRateLimiter
impl ApiRateLimiter
Sourcepub fn new(requests_per_second: u32) -> Self
pub fn new(requests_per_second: u32) -> Self
Create API rate limiter with requests per second limit
Sourcepub fn try_request(&self) -> bool
pub fn try_request(&self) -> bool
Try to make a request - returns true if allowed
Sourcepub fn try_requests(&self, n: u32) -> bool
pub fn try_requests(&self, n: u32) -> bool
Try to make N requests - returns true if all allowed
Sourcepub fn current_rate(&self) -> f64
pub fn current_rate(&self) -> f64
Get current rate
Sourcepub fn total_requests(&self) -> u64
pub fn total_requests(&self) -> u64
Get total requests
Sourcepub fn is_over_limit(&self) -> bool
pub fn is_over_limit(&self) -> bool
Check if currently over limit
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ApiRateLimiter
impl RefUnwindSafe for ApiRateLimiter
impl Send for ApiRateLimiter
impl Sync for ApiRateLimiter
impl Unpin for ApiRateLimiter
impl UnwindSafe for ApiRateLimiter
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