pub struct RateLimiter {
pub limit: RateLimit,
/* private fields */
}Expand description
Enforces a RateLimit by maintaining a ring vector of
timestamps capped at the RateLimit::count.
Fields§
§limit: RateLimitImplementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(limit: RateLimit) -> RateLimiter
pub fn new(limit: RateLimit) -> RateLimiter
Create without preallocating storage. Ideal if it may go unused.
Sourcepub fn new_preallocated(limit: RateLimit) -> RateLimiter
pub fn new_preallocated(limit: RateLimit) -> RateLimiter
Create with preallocated storage. Ideal if you’re likely to use it a lot to avoid resizing during fill.
Sourcepub fn check(&mut self) -> bool
pub fn check(&mut self) -> bool
Checks whether we’re able to perform the event at this time. On success, logs the current time to count towards future enforcement.
Sourcepub fn check_at(&mut self, instant: Instant) -> bool
pub fn check_at(&mut self, instant: Instant) -> bool
Like RateLimiter::check, but you can provide an arbitrary
timestamp (useful for tests!).
Warning: do not go backwards in time, things will mess up.
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