pub struct KeyedRateLimiter<K>where
K: Ord,{ /* private fields */ }
Expand description
A rate limiter that utilizes a BTreeMap to map K -> SlidingWindowRateLimiter, allowing for a per-argument rate limiter.
This is used for several endpoints that are rate limited by IP and trading pair, so each pair is given a unique rate limiter.
Implementations§
Source§impl<K> KeyedRateLimiter<K>where
K: Ord,
impl<K> KeyedRateLimiter<K>where
K: Ord,
Sourcepub fn add_rate_limiter(
&mut self,
key: K,
rate_limiter: SlidingWindowRateLimiter,
) -> Option<SlidingWindowRateLimiter>
pub fn add_rate_limiter( &mut self, key: K, rate_limiter: SlidingWindowRateLimiter, ) -> Option<SlidingWindowRateLimiter>
Add a rate limiter implementation for a given key, such that self.wait_until_ready(key)
will use this rate limiter.
This can overwrite previous rate limiters if the key already exists and returns/follows the same semantics as BTreeMap’s insert method.
Sourcepub fn remove_rate_limiter(
&mut self,
key: &K,
) -> Option<SlidingWindowRateLimiter>
pub fn remove_rate_limiter( &mut self, key: &K, ) -> Option<SlidingWindowRateLimiter>
Remove a rate limiter from the internal map. This may result in subsequent usages of this key using a default rate limiter.
This follows the same return semantics as BTreeMap’s remove method.
Sourcepub async fn wait_until_ready(&mut self, key: K)
pub async fn wait_until_ready(&mut self, key: K)
Follows the same semantics as SlidingWindowRateLimiter, except it looks up a rate limiter by key, and creates a rate limiter if none is found.
Sourcepub async fn wait_with_cost(&mut self, cost: usize, key: K)
pub async fn wait_with_cost(&mut self, cost: usize, key: K)
Follows the same semantics as SlidingWindowRateLimiter, except it looks up a rate limiter by key, and creates a rate limiter if none is found.
Trait Implementations§
Source§impl<K> Clone for KeyedRateLimiter<K>
impl<K> Clone for KeyedRateLimiter<K>
Source§fn clone(&self) -> KeyedRateLimiter<K>
fn clone(&self) -> KeyedRateLimiter<K>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more