[−][src]Struct simple_rate_limit::RateLimiter
Enforces a RateLimit
by maintaining a ring vector of
timestamps capped at the RateLimit::count
.
Fields
limit: RateLimit
Implementations
impl RateLimiter
[src]
pub fn new(limit: RateLimit) -> RateLimiter
[src]
Create without preallocating storage. Ideal if it may go unused.
pub fn new_preallocated(limit: RateLimit) -> RateLimiter
[src]
Create with preallocated storage. Ideal if you're likely to use it a lot to avoid resizing during fill.
pub fn check(&mut self) -> bool
[src]
Checks whether we're able to perform the event at this time. On success, logs the current time to count towards future enforcement.
pub fn check_at(&mut self, instant: Instant) -> bool
[src]
Like RateLimiter::check
, but you can provide an arbitrary
timestamp (useful for tests!).
Warning: do not go backwards in time, things will mess up.
pub fn sweep(&mut self, instant: Instant) -> bool
[src]
Auto Trait Implementations
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnwindSafe for RateLimiter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,