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
impl StatusSet
Sourcepub const DEFAULT: Self
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.
Sourcepub const fn contains(&self, status: u16) -> bool
pub const fn contains(&self, status: u16) -> bool
Whether status is in the set; always false from 640 up.
Sourcepub const fn insert(&mut self, status: u16) -> bool
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.
Trait Implementations§
impl Copy for StatusSet
Source§impl Default for StatusSet
impl Default for StatusSet
Source§fn default() -> Self
fn default() -> Self
StatusSet::DEFAULT, the statuses retried unless a policy says
otherwise.
impl Eq for StatusSet
Source§impl Extend<u16> for StatusSet
impl Extend<u16> for StatusSet
Source§fn extend<I: IntoIterator<Item = u16>>(&mut self, statuses: I)
fn extend<I: IntoIterator<Item = u16>>(&mut self, statuses: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<u16> for StatusSet
impl FromIterator<u16> for StatusSet
Source§fn from_iter<I: IntoIterator<Item = u16>>(statuses: I) -> Self
fn from_iter<I: IntoIterator<Item = u16>>(statuses: I) -> Self
Exactly the statuses given; one of 640 or more is left out.
impl StructuralPartialEq for StatusSet
Auto Trait Implementations§
impl Freeze for StatusSet
impl RefUnwindSafe for StatusSet
impl Send for StatusSet
impl Sync for StatusSet
impl Unpin for StatusSet
impl UnsafeUnpin for StatusSet
impl UnwindSafe for StatusSet
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.