Skip to main content

Class

Enum Class 

Source
#[non_exhaustive]
pub enum Class { Network, Unavailable { code: Option<Arc<str>>, }, RateLimited { retry_after: Option<Duration>, }, Unauthorized, InvalidRequest, VenueRefusal { code: Option<Arc<str>>, }, Restricted, Decode, }
Expand description

What kind of failure an error is, whichever venue or transport produced it.

A caller decides whether to retry, back off, alert or give up from the class alone, so one policy serves every crate. An HTTP status decides the class before any body does (see class_for_status).

code fields hold the venue’s own error code, never the HTTP status, with numeric codes written in decimal.

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.
§

Network

No response arrived: a failed connect, a timeout, a reset, a TLS EOF, a DNS failure, or a socket that closed.

§

Unavailable

The host is unwell or busy: a 408, 425 or 5xx, whatever the body says.

Fields

§code: Option<Arc<str>>

The venue’s error code, when it sent one.

§

RateLimited

A 429.

Fields

§retry_after: Option<Duration>

How long the server asked the caller to wait.

§

Unauthorized

A 401 or 403: the credentials were missing, wrong or not allowed.

§

InvalidRequest

The client refused the request itself, or was misused: local validation, a bad URL, a socket used after it closed. No status ever produces it.

§

VenueRefusal

The venue refused the request: any 4xx without a class of its own, or a socket closed with a protocol or application close code.

Fields

§code: Option<Arc<str>>

The venue’s error code, when it sent one.

§

Restricted

The venue will not serve this caller: a 418 ban, a 451 region block, or a firewall refusal a venue documents as one.

§

Decode

A successful response, or a frame, that did not parse.

Implementations§

Source§

impl Class

Source

pub fn is_retriable(&self) -> bool

Whether retrying could plausibly succeed: true for Network, Unavailable and RateLimited.

This describes the failure, not the operation. A retriable error on an order placement still needs the caller to judge whether resubmitting is safe.

Source

pub fn retry_after(&self) -> Option<Duration>

The wait a RateLimited class carries, and None for every other class and for a zero wait.

Source

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

The venue’s code, for Unavailable and VenueRefusal.

Source

pub fn with_code(self, code: impl Into<Arc<str>>) -> Self

Sets the venue’s code on Unavailable and VenueRefusal. Every other class is returned unchanged, since it has nowhere to put one.

Source

pub fn with_retry_after(self, retry_after: Option<Duration>) -> Self

Sets the wait on RateLimited. A zero wait is dropped, since it asks for nothing. Every other class is returned unchanged.

Trait Implementations§

Source§

impl Clone for Class

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 Debug for Class

Source§

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

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

impl Eq for Class

Source§

impl Hash for Class

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 Class

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 Class

Auto Trait Implementations§

§

impl Freeze for Class

§

impl RefUnwindSafe for Class

§

impl Send for Class

§

impl Sync for Class

§

impl Unpin for Class

§

impl UnsafeUnpin for Class

§

impl UnwindSafe for Class

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.