pub struct RateLimit { /* private fields */ }Expand description
The rate-limit facts one response’s own headers carried.
Every figure is optional because every one of them is absent from some real response: a request that never reached GitHub has no headers at all, and a refusal from an intermediary carries whichever of them that intermediary felt like carrying. An absent figure is reported as unknown rather than guessed at.
These are observations of one response, so the only ways to have one are to observe a
response (RateLimit::read) or to have observed nothing (RateLimit::default).
The fields are read through the accessors below rather than assembled: a hand-built set
could say the account had more remaining than its whole allowance, or name a resource
GitHub would never name, and a report built on it would be a measurement of nothing.
Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn read(header: impl Fn(&str) -> Option<String>) -> Self
pub fn read(header: impl Fn(&str) -> Option<String>) -> Self
Read the five headers GitHub carries a budget’s state in.
header is given a lower-case header name and answers that response’s value for
it. Taking a lookup rather than a header map is what keeps the HTTP client this
crate happens to use out of its public interface, so a caller sending its own
requests with its own client records into the same accounting.
Sourcepub const fn limit(&self) -> Option<u64>
pub const fn limit(&self) -> Option<u64>
The whole allowance for this budget’s window, as this response reported it.
Sourcepub const fn used_by_the_account(&self) -> Option<u64>
pub const fn used_by_the_account(&self) -> Option<u64>
What the account had spent — not what this session spent, because other work draws on the same budget in the same window.
Sourcepub fn resource(&self) -> Option<&str>
pub fn resource(&self) -> Option<&str>
Which budget GitHub said these figures were about, when it named one it spells.
Sourcepub fn exhausted(&self) -> bool
pub fn exhausted(&self) -> bool
Whether these headers say the budget is exactly spent, which is what
Outcome::of_response reads.