pub struct RateLimitInfo {
pub limit: u64,
pub remaining: u64,
pub reset: u64,
pub retry_after: Option<u64>,
}Expand description
Structured rate-limit metadata matching X-RateLimit-* headers.
| Field | HTTP header | Meaning |
|---|---|---|
limit | X-RateLimit-Limit | Max requests allowed in the window |
remaining | X-RateLimit-Remaining | Requests still available |
reset | X-RateLimit-Reset | Unix timestamp when the window resets |
retry_after | Retry-After | Seconds to wait before retrying (429) |
Fields§
§limit: u64Maximum number of requests allowed in the current window.
remaining: u64Number of requests remaining in the current window.
reset: u64Unix timestamp (seconds) at which the current window resets.
retry_after: Option<u64>Seconds the client should wait before retrying (present on 429 responses).
Implementations§
Source§impl RateLimitInfo
impl RateLimitInfo
Sourcepub fn new(limit: u64, remaining: u64, reset: u64) -> Self
pub fn new(limit: u64, remaining: u64, reset: u64) -> Self
Create a new RateLimitInfo.
§Examples
use api_bones::ratelimit::RateLimitInfo;
let info = RateLimitInfo::new(100, 50, 1_700_000_000);
assert_eq!(info.limit, 100);
assert_eq!(info.remaining, 50);
assert!(info.retry_after.is_none());Sourcepub fn retry_after(self, seconds: u64) -> Self
pub fn retry_after(self, seconds: u64) -> Self
Set the retry_after hint (builder-style).
§Examples
use api_bones::ratelimit::RateLimitInfo;
let info = RateLimitInfo::new(100, 0, 1_700_000_000).retry_after(60);
assert_eq!(info.retry_after, Some(60));Sourcepub fn is_exceeded(&self) -> bool
pub fn is_exceeded(&self) -> bool
Return true when no requests remain in the current window.
§Examples
use api_bones::ratelimit::RateLimitInfo;
let exceeded = RateLimitInfo::new(100, 0, 1_700_000_000);
assert!(exceeded.is_exceeded());
let available = RateLimitInfo::new(100, 50, 1_700_000_000);
assert!(!available.is_exceeded());Trait Implementations§
Source§impl Clone for RateLimitInfo
impl Clone for RateLimitInfo
Source§fn clone(&self) -> RateLimitInfo
fn clone(&self) -> RateLimitInfo
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 RateLimitInfo
impl Debug for RateLimitInfo
Source§impl<'de> Deserialize<'de> for RateLimitInfo
impl<'de> Deserialize<'de> for RateLimitInfo
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 PartialEq for RateLimitInfo
impl PartialEq for RateLimitInfo
Source§impl Serialize for RateLimitInfo
impl Serialize for RateLimitInfo
impl Eq for RateLimitInfo
impl StructuralPartialEq for RateLimitInfo
Auto Trait Implementations§
impl Freeze for RateLimitInfo
impl RefUnwindSafe for RateLimitInfo
impl Send for RateLimitInfo
impl Sync for RateLimitInfo
impl Unpin for RateLimitInfo
impl UnsafeUnpin for RateLimitInfo
impl UnwindSafe for RateLimitInfo
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