pub struct KeyedRateLimiter<K> { /* private fields */ }Expand description
64-way cache-line-aligned sharded, bounded, lock-free-CAS keyed rate limiter.
Implementations§
Source§impl<K> KeyedRateLimiter<K>
Core 64-way sharded bounded rate-limiting operations for KeyedRateLimiter.
impl<K> KeyedRateLimiter<K>
Core 64-way sharded bounded rate-limiting operations for KeyedRateLimiter.
Sourcepub fn new(
policy: RateLimitPolicy,
max_entries: usize,
) -> Result<Self, RateLimitError>
pub fn new( policy: RateLimitPolicy, max_entries: usize, ) -> Result<Self, RateLimitError>
Sourcepub fn with_clock(
policy: RateLimitPolicy,
max_entries: usize,
clock: MonotonicClock,
) -> Result<Self, RateLimitError>
pub fn with_clock( policy: RateLimitPolicy, max_entries: usize, clock: MonotonicClock, ) -> Result<Self, RateLimitError>
Sourcepub fn get_policy(&self) -> RateLimitPolicy
pub fn get_policy(&self) -> RateLimitPolicy
Sourcepub fn get_clock(&self) -> &MonotonicClock
pub fn get_clock(&self) -> &MonotonicClock
Sourcepub fn get_max_entries(&self) -> usize
pub fn get_max_entries(&self) -> usize
Sourcepub fn get_per_shard_capacity(&self) -> usize
pub fn get_per_shard_capacity(&self) -> usize
Sourcepub fn effective_capacity(&self) -> usize
pub fn effective_capacity(&self) -> usize
Returns the effective upper bound across all 64 shards (64 * per_shard_capacity).
§Returns
usize- Total hard bound across all shards.
Sourcepub fn check<Q>(&self, key: &Q) -> RateLimitDecision
pub fn check<Q>(&self, key: &Q) -> RateLimitDecision
Sourcepub fn check_n<Q>(&self, key: &Q, cost: u64) -> RateLimitDecision
pub fn check_n<Q>(&self, key: &Q, cost: u64) -> RateLimitDecision
Sourcepub fn check_at_ns<Q>(&self, key: &Q, now_ns: u64) -> RateLimitDecision
pub fn check_at_ns<Q>(&self, key: &Q, now_ns: u64) -> RateLimitDecision
Sourcepub fn check_n_at_ns<Q>(
&self,
key: &Q,
now_ns: u64,
cost: u64,
) -> RateLimitDecision
pub fn check_n_at_ns<Q>( &self, key: &Q, now_ns: u64, cost: u64, ) -> RateLimitDecision
Checks and consumes cost units for key at an explicit monotonic timestamp.
§Arguments
&Q- Borrowed key reference (zero allocation on existing keys).u64- Monotonic timestamp in nanoseconds.u64- Number of quota units to consume.
§Returns
RateLimitDecision- Admission decision and nanosecond timings.
Sourcepub fn peek<Q>(&self, key: &Q) -> RateLimitDecision
pub fn peek<Q>(&self, key: &Q) -> RateLimitDecision
Sourcepub fn peek_at_ns<Q>(&self, key: &Q, now_ns: u64) -> RateLimitDecision
pub fn peek_at_ns<Q>(&self, key: &Q, now_ns: u64) -> RateLimitDecision
Sourcepub fn evict_idle(&self) -> usize
pub fn evict_idle(&self) -> usize
Evicts all currently idle entries across all 64 shards using the embedded monotonic clock.
§Returns
usize- Total number of evicted keys.
Sourcepub fn evict_idle_at_ns(&self, now_ns: u64) -> usize
pub fn evict_idle_at_ns(&self, now_ns: u64) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<K> !Freeze for KeyedRateLimiter<K>
impl<K> !RefUnwindSafe for KeyedRateLimiter<K>
impl<K> Forget for KeyedRateLimiter<K>
impl<K> Move for KeyedRateLimiter<K>
impl<K> Send for KeyedRateLimiter<K>
impl<K> Sync for KeyedRateLimiter<K>
impl<K> Unpin for KeyedRateLimiter<K>
impl<K> UnsafeUnpin for KeyedRateLimiter<K>where
Align8<usize>: UnsafeUnpin,
*const [ReaderSlot] is !null: UnsafeUnpin,
PhantomData<[ReaderSlot]>: UnsafeUnpin,
*const [KeyedShard<K>] is !null: UnsafeUnpin,
PhantomData<[KeyedShard<K>]>: UnsafeUnpin,
impl<K> UnwindSafe for KeyedRateLimiter<K>where
Align8<usize>: UnwindSafe,
BoxRaw<[ReaderSlot]>: UnwindSafe,
BoxRaw<[KeyedShard<K>]>: UnwindSafe,
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