pub struct RateLimitState {
pub limit: u32,
pub remaining: u32,
pub reset: u64,
pub used: u32,
pub resource: RateLimitResource,
}Expand description
Rate limit state for a specific user/resource.
Fields§
§limit: u32Maximum requests allowed.
remaining: u32Remaining requests in current window.
reset: u64Unix timestamp when the limit resets.
used: u32Requests used in current window.
resource: RateLimitResourceResource type.
Implementations§
Source§impl RateLimitState
impl RateLimitState
Sourcepub fn new(limit: u32, resource: RateLimitResource) -> Self
pub fn new(limit: u32, resource: RateLimitResource) -> Self
Create a new rate limit state.
Sourcepub fn is_exceeded(&self) -> bool
pub fn is_exceeded(&self) -> bool
Check if the rate limit is exceeded.
Sourcepub fn reset_window(&mut self)
pub fn reset_window(&mut self)
Reset the window.
Sourcepub fn time_until_reset(&self) -> u64
pub fn time_until_reset(&self) -> u64
Get the time until reset in seconds.
Trait Implementations§
Source§impl Clone for RateLimitState
impl Clone for RateLimitState
Source§fn clone(&self) -> RateLimitState
fn clone(&self) -> RateLimitState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 RateLimitState
impl Debug for RateLimitState
Source§impl<'de> Deserialize<'de> for RateLimitState
impl<'de> Deserialize<'de> for RateLimitState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&RateLimitState> for RateLimitInfo
impl From<&RateLimitState> for RateLimitInfo
Source§fn from(state: &RateLimitState) -> Self
fn from(state: &RateLimitState) -> Self
Converts to this type from the input type.
Source§impl From<&RateLimitState> for RateLimitHeaders
impl From<&RateLimitState> for RateLimitHeaders
Source§fn from(state: &RateLimitState) -> Self
fn from(state: &RateLimitState) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for RateLimitState
impl RefUnwindSafe for RateLimitState
impl Send for RateLimitState
impl Sync for RateLimitState
impl Unpin for RateLimitState
impl UnsafeUnpin for RateLimitState
impl UnwindSafe for RateLimitState
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