Skip to main content

StatusSet

Struct StatusSet 

Source
pub struct StatusSet(/* private fields */);
Expand description

A set of HTTP status codes, as a fixed bitmap: copying one costs 80 bytes and looking a status up costs a shift, with no allocation either way.

It holds 0 to 639, which covers every status HTTP defines (100 to 599). A status of 640 or more is never contained, and inserting one does nothing and returns false.

In a RetryPolicy the set is asked only about responses reported as ErrorKind::Api, so a success status in it has no effect; see RetryPolicy::http_statuses.

use typesafe_sdk::StatusSet;

let mut statuses = StatusSet::DEFAULT;
assert!(statuses.contains(503));
statuses.remove(503);
statuses.insert(409);
assert_eq!(format!("{statuses:?}"), "{408, 409, 429, 500..=502, 504..=599}");

let only = [429, 503].into_iter().collect::<StatusSet>();
assert_eq!(only.iter().collect::<Vec<_>>(), [429, 503]);

Implementations§

Source§

impl StatusSet

Source

pub const DEFAULT: Self

The statuses retried by default, as in the Python SDK: 408 (request timeout), 429 (too many requests) and every 5xx, 500 to 599.

Source

pub const fn empty() -> Self

A set with no status in it.

Source

pub const fn contains(&self, status: u16) -> bool

Whether status is in the set; always false from 640 up.

Source

pub const fn insert(&mut self, status: u16) -> bool

Adds status, and says whether it was not there before. A status of 640 or more cannot be held: nothing changes and the answer is false.

Source

pub const fn remove(&mut self, status: u16) -> bool

Removes status, and says whether it was there.

Source

pub const fn is_empty(&self) -> bool

Whether the set holds no status.

Source

pub fn iter(&self) -> impl Iterator<Item = u16> + use<>

The statuses in the set, from the lowest up.

Trait Implementations§

Source§

impl Clone for StatusSet

Source§

fn clone(&self) -> Self

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 Copy for StatusSet

Source§

impl Debug for StatusSet

Source§

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

{408, 429, 500..=599}: a run of three or more statuses prints as a range.

Source§

impl Default for StatusSet

Source§

fn default() -> Self

StatusSet::DEFAULT, the statuses retried unless a policy says otherwise.

Source§

impl Eq for StatusSet

Source§

impl Extend<u16> for StatusSet

Source§

fn extend<I: IntoIterator<Item = u16>>(&mut self, statuses: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<u16> for StatusSet

Source§

fn from_iter<I: IntoIterator<Item = u16>>(statuses: I) -> Self

Exactly the statuses given; one of 640 or more is left out.

Source§

impl Hash for StatusSet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for StatusSet

Source§

fn eq(&self, other: &Self) -> 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 StatusSet

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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