pub struct RateLimiter<'a, T: 'a + Store> {
pub store: &'a mut T,
/* private fields */
}
Fields§
§store: &'a mut T
Implementations§
Source§impl<'a, T: 'a + Store> RateLimiter<'a, T>
impl<'a, T: 'a + Store> RateLimiter<'a, T>
pub fn new(store: &'a mut T, quota: &RateQuota) -> RateLimiter<'a, T>
Sourcepub fn rate_limit(
&mut self,
key: &str,
quantity: i64,
) -> Result<(bool, RateLimitResult), CellError>
pub fn rate_limit( &mut self, key: &str, quantity: i64, ) -> Result<(bool, RateLimitResult), CellError>
RateLimit checks whether a particular key has exceeded a rate limit. It also returns a RateLimitResult to provide additional information about the state of the RateLimiter.
If the rate limit has not been exceeded, the underlying storage is updated by the supplied quantity. For example, a quantity of 1 might be used to rate limit a single request while a greater quantity could rate limit based on the size of a file upload in megabytes. If quantity is 0, no update is performed allowing you to “peek” at the state of the RateLimiter for a given key.
Auto Trait Implementations§
impl<'a, T> Freeze for RateLimiter<'a, T>
impl<'a, T> RefUnwindSafe for RateLimiter<'a, T>where
T: RefUnwindSafe,
impl<'a, T> Send for RateLimiter<'a, T>where
T: Send,
impl<'a, T> Sync for RateLimiter<'a, T>where
T: Sync,
impl<'a, T> Unpin for RateLimiter<'a, T>
impl<'a, T> !UnwindSafe for RateLimiter<'a, T>
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