pub struct RateLimiter { /* private fields */ }Expand description
Aggregate rate limiter coordinating in-memory throttling with persisted usage counters.
Implementations§
Source§impl RateLimiter
impl RateLimiter
pub async fn new( paths: ConfigPaths, account: &str, config: RateLimitConfig, ) -> Result<Self, RateLimitError>
Sourcepub async fn acquire(&self, weight: NonZeroU32)
pub async fn acquire(&self, weight: NonZeroU32)
Wait until the configured quota permits executing weight cost units.
Sourcepub async fn record_success(
&self,
weight: u32,
now: OffsetDateTime,
) -> Result<RateStatus, RateLimitError>
pub async fn record_success( &self, weight: u32, now: OffsetDateTime, ) -> Result<RateStatus, RateLimitError>
Record a successful request, updating persisted counters.
Sourcepub async fn status(
&self,
now: OffsetDateTime,
) -> Result<RateStatus, RateLimitError>
pub async fn status( &self, now: OffsetDateTime, ) -> Result<RateStatus, RateLimitError>
Retrieve the current counter status without mutating state.
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§fn clone(&self) -> RateLimiter
fn clone(&self) -> RateLimiter
Returns a duplicate of the value. Read more
1.0.0 · 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 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