pub struct MemoryRateLimitCounter { /* private fields */ }Expand description
A DashMap-backed RateLimitCounter.
Each key tracks a count and the wall-clock start of its current window;
once the window elapses the count rolls over to zero on the next access.
DashMap’s per-key entry lock makes the read-modify-write in
increment atomic across concurrent callers.
Cloning shares the same underlying map.
Implementations§
Trait Implementations§
Source§impl Clone for MemoryRateLimitCounter
impl Clone for MemoryRateLimitCounter
Source§fn clone(&self) -> MemoryRateLimitCounter
fn clone(&self) -> MemoryRateLimitCounter
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for MemoryRateLimitCounter
impl Default for MemoryRateLimitCounter
Source§fn default() -> MemoryRateLimitCounter
fn default() -> MemoryRateLimitCounter
Returns the “default value” for a type. Read more
Source§impl RateLimitCounter for MemoryRateLimitCounter
impl RateLimitCounter for MemoryRateLimitCounter
Source§fn increment<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
amount: u64,
window_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn increment<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
amount: u64,
window_secs: u64,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Atomically add
amount to the counter for key within the window of
length window_secs, returning the new total for the current window. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for MemoryRateLimitCounter
impl !UnwindSafe for MemoryRateLimitCounter
impl Freeze for MemoryRateLimitCounter
impl Send for MemoryRateLimitCounter
impl Sync for MemoryRateLimitCounter
impl Unpin for MemoryRateLimitCounter
impl UnsafeUnpin for MemoryRateLimitCounter
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