pub struct UserRateLimiter { /* private fields */ }Expand description
Per-user rate limiter with tier-based quotas
Implementations§
Source§impl UserRateLimiter
impl UserRateLimiter
Sourcepub async fn set_user_tier(&self, user_id: &str, tier: UserTier)
pub async fn set_user_tier(&self, user_id: &str, tier: UserTier)
Set a user’s tier
Sourcepub async fn get_user_tier(&self, user_id: &str) -> UserTier
pub async fn get_user_tier(&self, user_id: &str) -> UserTier
Get a user’s current tier
Sourcepub async fn try_acquire(&self, user_id: &str) -> Result<(), RateLimitError>
pub async fn try_acquire(&self, user_id: &str) -> Result<(), RateLimitError>
Try to acquire a permit for a user
Sourcepub async fn try_acquire_with_tokens(
&self,
user_id: &str,
estimated_tokens: u32,
) -> Result<(), RateLimitError>
pub async fn try_acquire_with_tokens( &self, user_id: &str, estimated_tokens: u32, ) -> Result<(), RateLimitError>
Try to acquire a permit with estimated tokens for a user
Sourcepub async fn user_stats(&self, user_id: &str) -> UserRateLimitStats
pub async fn user_stats(&self, user_id: &str) -> UserRateLimitStats
Get usage stats for a user
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for UserRateLimiter
impl !RefUnwindSafe for UserRateLimiter
impl Send for UserRateLimiter
impl Sync for UserRateLimiter
impl Unpin for UserRateLimiter
impl !UnwindSafe for UserRateLimiter
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