pub struct RateLimiter { /* private fields */ }Expand description
Shared concurrent rate-limiter state.
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
Admission check for a new request. estimated_tokens is the
caller’s best guess at how many tokens this call will burn
(prompt + max completion). Streaming callers pass their worst-case
so the reservation is conservative; on completion they call
refund_tokens with the true-up.
Sourcepub fn refund_tokens(&self, key: &str, amount: u64)
pub fn refund_tokens(&self, key: &str, amount: u64)
Called after a streaming request completes with (reserved - actual)
so over-estimated reservations don’t burn the token bucket forever.
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