Skip to main content

RateLimit

Struct RateLimit 

Source
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

Source

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.

Source

pub const fn limit(&self) -> Option<u64>

The whole allowance for this budget’s window, as this response reported it.

Source

pub const fn remaining(&self) -> Option<u64>

What was left of it when GitHub answered.

Source

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.

Source

pub const fn reset(&self) -> Option<u64>

The Unix second the allowance comes back.

Source

pub fn resource(&self) -> Option<&str>

Which budget GitHub said these figures were about, when it named one it spells.

Source

pub fn exhausted(&self) -> bool

Whether these headers say the budget is exactly spent, which is what Outcome::of_response reads.

Trait Implementations§

Source§

impl Clone for RateLimit

Source§

fn clone(&self) -> RateLimit

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RateLimit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RateLimit

Source§

fn default() -> RateLimit

Returns the “default value” for a type. Read more
Source§

impl Eq for RateLimit

Source§

impl PartialEq for RateLimit

Source§

fn eq(&self, other: &RateLimit) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RateLimit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more