#[non_exhaustive]pub enum RatelimitHeaders {
Global(Global),
None,
Present(Present),
}
Expand description
Parsed headers.
The headers of a response may either indicate a global ratelimit, a bucketed ratelimit, or no ratelimit at all.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Global(Global)
Global ratelimit encountered.
None
No ratelimit headers present.
Present(Present)
Bucketed ratelimit present.
Implementations§
source§impl RatelimitHeaders
impl RatelimitHeaders
sourcepub const fn is_present(&self) -> bool
pub const fn is_present(&self) -> bool
Whether the ratelimit headers are for a bucket.
sourcepub fn from_pairs<'a>(
headers: impl Iterator<Item = (&'a str, &'a [u8])>,
) -> Result<Self, HeaderParsingError>
pub fn from_pairs<'a>( headers: impl Iterator<Item = (&'a str, &'a [u8])>, ) -> Result<Self, HeaderParsingError>
Parse headers from an iterator of tuples containing the header name and value.
Headers names must be lowercase.
§Examples
Parse a standard list of headers from a response:
use twilight_http_ratelimiting::RatelimitHeaders;
let headers = [
(
"x-ratelimit-bucket",
"d721dea6054f6322373d361f98e5c38b".as_bytes(),
),
("x-ratelimit-limit", "10".as_bytes()),
("x-ratelimit-remaining", "9".as_bytes()),
("x-ratelimit-reset", "1573795260.333".as_bytes()),
("x-ratelimit-reset-after", "10.000".as_bytes()),
];
let headers = RatelimitHeaders::from_pairs(headers.into_iter())?;
assert!(matches!(
headers,
RatelimitHeaders::Present(p) if p.remaining() == 9,
));
Parse a list of headers denoting that the user has been globally ratelimited:
use twilight_http_ratelimiting::RatelimitHeaders;
let headers = [
("retry-after", "487".as_bytes()),
("x-ratelimit-global", "true".as_bytes()),
];
let headers = RatelimitHeaders::from_pairs(headers.into_iter())?;
assert!(matches!(
headers,
RatelimitHeaders::Global(g) if g.retry_after() == 487,
));
§Errors
Errors if a required header is missing or if a header value is of an invalid type.
Trait Implementations§
source§impl Clone for RatelimitHeaders
impl Clone for RatelimitHeaders
source§fn clone(&self) -> RatelimitHeaders
fn clone(&self) -> RatelimitHeaders
Returns a copy 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 moreAuto Trait Implementations§
impl Freeze for RatelimitHeaders
impl RefUnwindSafe for RatelimitHeaders
impl Send for RatelimitHeaders
impl Sync for RatelimitHeaders
impl Unpin for RatelimitHeaders
impl UnwindSafe for RatelimitHeaders
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)