pub struct RateLimiter { /* private fields */ }Expand description
2026-09-26: The limiter, shared across requests.
Implementations§
Source§impl RateLimiter
impl RateLimiter
pub fn config(&self) -> RateLimitConfig
Sourcepub fn admit(&self, key: &str, estimated_tokens: u64) -> RateDecision
pub fn admit(&self, key: &str, estimated_tokens: u64) -> RateDecision
2026-09-26: Admit or deny one request from key, debiting one request
and estimated_tokens tokens from the enforced buckets. The middleware
passes max_seq_len; handlers refund the unused part with
Self::refund_tokens.
Sourcepub fn refund_tokens(&self, key: &str, amount: u64)
pub fn refund_tokens(&self, key: &str, amount: u64)
2026-09-26: Return amount tokens to key’s token bucket, up to its
burst. No-op when the token bucket is disabled or the key was evicted.
Auto Trait Implementations§
impl !Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnwindSafe for RateLimiter
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more