pub struct RateLimit {
pub max_requests: usize,
pub interval: Duration,
/* private fields */
}Expand description
Rate limit information using token bucket algorithm
This implementation provides proper rate limiting with automatic window reset and thread-safe counter management.
Fields§
§max_requests: usizeMaximum requests per interval
interval: DurationTime interval for the rate limit window
Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn new(max_requests: usize, interval: Duration) -> Self
pub fn new(max_requests: usize, interval: Duration) -> Self
Create a new rate limit
§Arguments
max_requests- Maximum requests allowed per intervalinterval- Time window for rate limiting
Sourcepub fn can_proceed(&self) -> bool
pub fn can_proceed(&self) -> bool
Check if request can proceed and increment counter if allowed
Returns true if the request is within rate limits, false otherwise. This is a non-blocking, thread-safe operation using atomic operations.
Sourcepub fn current_count(&self) -> usize
pub fn current_count(&self) -> usize
Get the current count of requests in this window
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnwindSafe for RateLimit
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.