pub struct RateLimiter { /* private fields */ }Implementations§
Source§impl RateLimiter
impl RateLimiter
pub fn load( rate_to_ms_conversion: i32, consumed_tokens: i32, last_refill_time: i64, ) -> Self
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/ratelimiter.rs (line 15)
14fn ratelimiter() {
15 let mut limiter = RateLimiter::new();
16 let mut times = 0;
17 for _ in 0..3000 {
18 thread::sleep(Duration::from_millis(1));
19 if limiter.acquire(10, 10) {
20 times += 1;
21 println!("time: {}", now_millis())
22 } else {
23 continue;
24 }
25 }
26 println!("time: {}, times: {}", now_millis(), ×);
27}pub fn new_by_unit(unit: RateUnit) -> Self
pub fn new_by_conversion(rate_to_ms_conversion: i32) -> Self
Sourcepub fn acquire(&mut self, burst_size: i32, average_rate: i64) -> bool
pub fn acquire(&mut self, burst_size: i32, average_rate: i64) -> bool
Examples found in repository?
examples/ratelimiter.rs (line 19)
14fn ratelimiter() {
15 let mut limiter = RateLimiter::new();
16 let mut times = 0;
17 for _ in 0..3000 {
18 thread::sleep(Duration::from_millis(1));
19 if limiter.acquire(10, 10) {
20 times += 1;
21 println!("time: {}", now_millis())
22 } else {
23 continue;
24 }
25 }
26 println!("time: {}, times: {}", now_millis(), ×);
27}pub fn acquire_by_time( &mut self, burst_size: i32, average_rate: i64, current_time_millis: i64, ) -> bool
pub fn reset(&mut self)
pub fn get_rate_to_ms_conversion(&self) -> i32
pub fn get_consumed_tokens(&self) -> i32
pub fn get_last_refill_time(&self) -> i64
pub fn get_to_save(&self) -> (i32, i32, i64)
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 moreSource§impl Debug for RateLimiter
impl Debug for RateLimiter
Source§impl Default for RateLimiter
impl Default for RateLimiter
Source§fn default() -> RateLimiter
fn default() -> RateLimiter
Returns the “default value” for a type. Read more
Auto 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