pub struct RateLimiter { /* private fields */ }Implementations§
Source§impl RateLimiter
impl RateLimiter
pub async fn new( redis_url: Option<&str>, ) -> Result<Self, Box<dyn Error + Send + Sync>>
Sourcepub fn from_connection_manager(manager: ConnectionManager) -> Self
pub fn from_connection_manager(manager: ConnectionManager) -> Self
Create a RateLimiter from an existing ConnectionManager. This allows sharing a single Redis connection across subsystems.
pub async fn is_allowed( &self, key: &str, amount: u64, ) -> Result<bool, Box<dyn Error + Send + Sync>>
pub async fn is_allowed_with_quota( &self, key: &str, amount: u64, quota: Option<&Quota>, ) -> Result<bool, Box<dyn Error + Send + Sync>>
pub async fn check_rpm( &self, key: &str, limit: u64, ) -> Result<(bool, u64), Box<dyn Error + Send + Sync>>
pub async fn check_tpm( &self, key: &str, limit: u64, tokens: u64, ) -> Result<bool, Box<dyn Error + Send + Sync>>
Sourcepub async fn charge_tokens(
&self,
key: &str,
tokens: u64,
quota: Option<&Quota>,
) -> Result<bool, Box<dyn Error + Send + Sync>>
pub async fn charge_tokens( &self, key: &str, tokens: u64, quota: Option<&Quota>, ) -> Result<bool, Box<dyn Error + Send + Sync>>
Charge additional tokens against the TPM limiter (e.g., for actual usage that exceeded the pre-request estimate). Does not affect RPM.
pub async fn record_usage( &self, key: &str, tokens_used: u64, ) -> Result<(), Box<dyn Error + Send + Sync>>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for RateLimiter
impl !UnwindSafe for RateLimiter
impl Forget for RateLimiter
impl Freeze for RateLimiter
impl Move for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin 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
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