pub enum StatusCode {
Show 61 variants Continue, SwitchingProtocols, Processing, Ok, Created, Accepted, NonAuthoritativeInformation, NoContent, ResetContent, PartialContent, MultiStatus, AlreadyReported, ImUsed, MultipleChoices, MovedPermanently, Found, SeeOther, NotModified, UseProxy, TemporaryRedirect, PermanentRedirect, BadRequest, Unauthorized, PaymentRequired, Forbidden, NotFound, MethodNotAllowed, NotAcceptable, ProxyAuthenticationRequired, RequestTimeout, Conflict, Gone, LengthRequired, PreconditionFailed, PayloadTooLarge, UriTooLong, UnsupportedMediaType, RangeNotSatisfiable, ExpectationFailed, ImATeapot, MisdirectedRequest, UnprocessableEntity, Locked, FailedDependency, UpgradeRequired, PreconditionRequired, TooManyRequests, RequestHeaderFieldsTooLarge, UnavailableForLegalReasons, InternalServerError, NotImplemented, BadGateway, ServiceUnavailable, GatewayTimeout, HttpVersionNotSupported, VariantAlsoNegotiates, InsufficientStorage, LoopDetected, NotExtended, NetworkAuthenticationRequired, Unregistered(u16),
}
Expand description

An HTTP status code (status-code in RFC 7230 et al.).

This enum contains all common status codes and an Unregistered extension variant. It allows status codes in the range [0, 65535], as any u16 integer may be used as a status code for XHR requests. It is recommended to only use values between [100, 599], since only these are defined as valid status codes with a status class by HTTP.

If you encounter a status code that you do not know how to deal with, you should treat it as the x00 status code—e.g. for code 123, treat it as 100 (Continue). This can be achieved with self.class().default_code():

let status = StatusCode::Unregistered(123);
assert_eq!(status.class().default_code(), StatusCode::Continue);

IANA maintain the Hypertext Transfer Protocol (HTTP) Status Code Registry which is the source for this enum (with one exception, 418 I’m a teapot, which is inexplicably not in the register).

Variants§

§

Continue

100 Continue [RFC7231, Section 6.2.1]

§

SwitchingProtocols

101 Switching Protocols [RFC7231, Section 6.2.2]

§

Processing

102 Processing [RFC2518]

§

Ok

§

Created

201 Created [RFC7231, Section 6.3.2]

§

Accepted

202 Accepted [RFC7231, Section 6.3.3]

§

NonAuthoritativeInformation

203 Non-Authoritative Information [RFC7231, Section 6.3.4]

§

NoContent

204 No Content [RFC7231, Section 6.3.5]

§

ResetContent

205 Reset Content [RFC7231, Section 6.3.6]

§

PartialContent

206 Partial Content [RFC7233, Section 4.1]

§

MultiStatus

207 Multi-Status [RFC4918]

§

AlreadyReported

208 Already Reported [RFC5842]

§

ImUsed

226 IM Used [RFC3229]

§

MultipleChoices

300 Multiple Choices [RFC7231, Section 6.4.1]

§

MovedPermanently

301 Moved Permanently [RFC7231, Section 6.4.2]

§

Found

§

SeeOther

303 See Other [RFC7231, Section 6.4.4]

§

NotModified

304 Not Modified [RFC7232, Section 4.1]

§

UseProxy

305 Use Proxy [RFC7231, Section 6.4.5]

§

TemporaryRedirect

307 Temporary Redirect [RFC7231, Section 6.4.7]

§

PermanentRedirect

308 Permanent Redirect [RFC7238]

§

BadRequest

400 Bad Request [RFC7231, Section 6.5.1]

§

Unauthorized

401 Unauthorized [RFC7235, Section 3.1]

§

PaymentRequired

402 Payment Required [RFC7231, Section 6.5.2]

§

Forbidden

403 Forbidden [RFC7231, Section 6.5.3]

§

NotFound

404 Not Found [RFC7231, Section 6.5.4]

§

MethodNotAllowed

405 Method Not Allowed [RFC7231, Section 6.5.5]

§

NotAcceptable

406 Not Acceptable [RFC7231, Section 6.5.6]

§

ProxyAuthenticationRequired

407 Proxy Authentication Required [RFC7235, Section 3.2]

§

RequestTimeout

408 Request Timeout [RFC7231, Section 6.5.7]

§

Conflict

409 Conflict [RFC7231, Section 6.5.8]

§

Gone

§

LengthRequired

411 Length Required [RFC7231, Section 6.5.10]

§

PreconditionFailed

412 Precondition Failed [RFC7232, Section 4.2]

§

PayloadTooLarge

413 Payload Too Large [RFC7231, Section 6.5.11]

§

UriTooLong

414 URI Too Long [RFC7231, Section 6.5.12]

§

UnsupportedMediaType

415 Unsupported Media Type [RFC7231, Section 6.5.13]

§

RangeNotSatisfiable

416 Range Not Satisfiable [RFC7233, Section 4.4]

§

ExpectationFailed

417 Expectation Failed [RFC7231, Section 6.5.14]

§

ImATeapot

418 I’m a teapot [curiously, not registered by IANA, but RFC2324]

§

MisdirectedRequest

421 Misdirected Request RFC7540, Section 9.1.2

§

UnprocessableEntity

422 Unprocessable Entity [RFC4918]

§

Locked

423 Locked [RFC4918]

§

FailedDependency

424 Failed Dependency [RFC4918]

§

UpgradeRequired

426 Upgrade Required [RFC7231, Section 6.5.15]

§

PreconditionRequired

428 Precondition Required [RFC6585]

§

TooManyRequests

429 Too Many Requests [RFC6585]

§

RequestHeaderFieldsTooLarge

431 Request Header Fields Too Large [RFC6585]

§

UnavailableForLegalReasons

451 Unavailable For Legal Reasons [RFC7725]

§

InternalServerError

500 Internal Server Error [RFC7231, Section 6.6.1]

§

NotImplemented

501 Not Implemented [RFC7231, Section 6.6.2]

§

BadGateway

502 Bad Gateway [RFC7231, Section 6.6.3]

§

ServiceUnavailable

503 Service Unavailable [RFC7231, Section 6.6.4]

§

GatewayTimeout

504 Gateway Timeout [RFC7231, Section 6.6.5]

§

HttpVersionNotSupported

505 HTTP Version Not Supported [RFC7231, Section 6.6.6]

§

VariantAlsoNegotiates

506 Variant Also Negotiates [RFC2295]

§

InsufficientStorage

507 Insufficient Storage [RFC4918]

§

LoopDetected

508 Loop Detected [RFC5842]

§

NotExtended

510 Not Extended [RFC2774]

§

NetworkAuthenticationRequired

511 Network Authentication Required [RFC6585]

§

Unregistered(u16)

A status code not in the IANA HTTP status code registry or very well known

Implementations§

source§

impl StatusCode

source

pub fn canonical_reason(&self) -> Option<&'static str>

Get the standardised reason-phrase for this status code.

This is mostly here for servers writing responses, but could potentially have application at other times.

The reason phrase is defined as being exclusively for human readers. You should avoid deriving any meaning from it at all costs.

Bear in mind also that in HTTP/2.0 the reason phrase is abolished from transmission, and so this canonical reason phrase really is the only reason phrase you’ll find.

source

pub fn class(&self) -> StatusClass

Determine the class of a status code, based on its first digit.

source

pub fn is_informational(&self) -> bool

Check if class is Informational.

source

pub fn is_success(&self) -> bool

Check if class is Success.

source

pub fn is_redirection(&self) -> bool

Check if class is Redirection.

source

pub fn is_client_error(&self) -> bool

Check if class is ClientError.

source

pub fn is_server_error(&self) -> bool

Check if class is ServerError.

source

pub fn is_strange_status(&self) -> bool

Check if class is NoClass

Trait Implementations§

source§

impl Clone for StatusCode

source§

fn clone(&self) -> StatusCode

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for StatusCode

source§

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

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

impl Display for StatusCode

Formats the status code, including the canonical reason.

assert_eq!(format!("{}", ImATeapot), "418 I'm a teapot");
assert_eq!(format!("{}", Unregistered(123)),
           "123 <unknown status code>");
source§

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

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

impl Hash for StatusCode

source§

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

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 Ord for StatusCode

source§

fn cmp(&self, other: &StatusCode) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for StatusCode

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for StatusCode

source§

fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for StatusCode

source§

impl Eq for StatusCode

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, I> AsResult<T, I> for T
where I: Input,

source§

fn as_result(self) -> Result<T, ParseErr<I>>

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

§

impl<T> IntoCollection<T> for T

§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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> Typeable for T
where T: Any,

source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V