pub struct RateLimiter { /* private fields */ }
Expand description
Rate limiter based on Token Bucket algorithm.
It allows for number of charges in specified interval. It can be used to limit API calls or anywhere with restriction over number of request per interval.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(total_charges: usize, charge_every: Duration) -> RateLimiter
pub fn new(total_charges: usize, charge_every: Duration) -> RateLimiter
new rate limiter from charges and duration to renew them
// equals to 1000 requests every 60 seconds.
let limiter = RateLimiter::new(1000, time::Duration::from_secs(60));
Sourcepub fn with_rpm(rpm: usize) -> RateLimiter
pub fn with_rpm(rpm: usize) -> RateLimiter
new a limiter with number of requests per minute.
Sourcepub fn with_rps(rps: usize) -> RateLimiter
pub fn with_rps(rps: usize) -> RateLimiter
new a limiter with number of requests per second.
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§const fn clone_from(&mut self, source: &Self)
const 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