pub struct RateLimiter { /* private fields */ }Expand description
A rate limiter combining a concurrency cap and a per-minute request cap.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(max_concurrent: usize, max_requests_per_minute: usize) -> Self
pub fn new(max_concurrent: usize, max_requests_per_minute: usize) -> Self
Create a new rate limiter.
max_concurrent bounds in-flight requests (0 = unlimited) and
max_requests_per_minute bounds the per-minute admission rate
(0 = unlimited).
Sourcepub async fn try_acquire(&self) -> Result<RateLimitPermit, RateLimitError>
pub async fn try_acquire(&self) -> Result<RateLimitPermit, RateLimitError>
Try to acquire a permit to process one request.
Returns a guard that releases the concurrency slot when dropped, or a
RateLimitError if the request would exceed either limit.
Auto Trait Implementations§
impl !Freeze for RateLimiter
impl !RefUnwindSafe for RateLimiter
impl !UnwindSafe 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