pub struct RateLimit {
pub limit: Option<u64>,
pub remaining: Option<u64>,
pub reset_at: Option<OffsetDateTime>,
pub retry_after: Option<Duration>,
}Expand description
What a service told us about our remaining budget.
Parsed once, here, from the three conventions that cover almost every API in
practice: the IETF RateLimit-* draft headers, the widespread X-RateLimit-*
variants, and plain Retry-After.
Fields§
§limit: Option<u64>Requests allowed in the current window.
remaining: Option<u64>Requests still available.
reset_at: Option<OffsetDateTime>When the window resets.
retry_after: Option<Duration>How long the service asked us to wait before retrying.
Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn from_headers(headers: &Headers, now: OffsetDateTime) -> Self
pub fn from_headers(headers: &Headers, now: OffsetDateTime) -> Self
Read rate-limit metadata from response headers.
now is needed because Retry-After and some reset headers are relative;
it comes from the Clock port so this stays testable.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Whether the budget is exhausted.
Sourcepub fn wait_for(&self, now: OffsetDateTime) -> Option<Duration>
pub fn wait_for(&self, now: OffsetDateTime) -> Option<Duration>
How long to wait before the next attempt, if the service said anything useful.
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Whether this response carried any rate-limit information at all.
Trait Implementations§
impl Copy for RateLimit
impl Eq for RateLimit
impl StructuralPartialEq for RateLimit
Auto Trait Implementations§
impl Freeze for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnsafeUnpin 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