pub struct RateLimitState {
pub agent_id: String,
/* private fields */
}Expand description
Per-agent rate limit state.
Fields§
§agent_id: StringImplementations§
Source§impl RateLimitState
impl RateLimitState
pub fn new(agent_id: &str, max_tokens: u64, replenish_rate: u64) -> Self
Sourcepub fn check(&mut self, cost: u64) -> RateLimitDecision
pub fn check(&mut self, cost: u64) -> RateLimitDecision
Check if a request is allowed, consuming tokens if so.
Sourcepub fn bucket(&self) -> &TokenBucket
pub fn bucket(&self) -> &TokenBucket
Access the underlying bucket (for testing).
Sourcepub fn bucket_mut(&mut self) -> &mut TokenBucket
pub fn bucket_mut(&mut self) -> &mut TokenBucket
Access the underlying bucket mutably (for testing).
Trait Implementations§
Source§impl Clone for RateLimitState
impl Clone for RateLimitState
Source§fn clone(&self) -> RateLimitState
fn clone(&self) -> RateLimitState
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 moreAuto Trait Implementations§
impl Freeze for RateLimitState
impl RefUnwindSafe for RateLimitState
impl Send for RateLimitState
impl Sync for RateLimitState
impl Unpin for RateLimitState
impl UnsafeUnpin for RateLimitState
impl UnwindSafe for RateLimitState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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