Skip to main content

StatusCode

Enum StatusCode 

Source
#[non_exhaustive]
pub enum StatusCode {
Show 62 variants Continue, SwitchingProtocols, Processing, EarlyHints, 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, ContentTooLarge, UriTooLong, UnsupportedMediaType, RangeNotSatisfiable, ExpectationFailed, ImATeapot, MisdirectedRequest, UnprocessableContent, Locked, FailedDependency, TooEarly, UpgradeRequired, PreconditionRequired, TooManyRequests, RequestHeaderFieldsTooLarge, UnavailableForLegalReasons, InternalServerError, NotImplemented, BadGateway, ServiceUnavailable, GatewayTimeout, HttpVersionNotSupported, VariantAlsoNegotiates, InsufficientStorage, LoopDetected, NotExtended, NetworkAuthenticationRequired,
}
Expand description

All standard HTTP status codes (RFC 9110 + common extensions).

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

Continue

100 Continue

§

SwitchingProtocols

101 Switching Protocols

§

Processing

102 Processing (WebDAV)

§

EarlyHints

103 Early Hints

§

Ok

200 OK

§

Created

201 Created

§

Accepted

202 Accepted

§

NonAuthoritativeInformation

203 Non-Authoritative Information

§

NoContent

204 No Content

§

ResetContent

205 Reset Content

§

PartialContent

206 Partial Content

§

MultiStatus

207 Multi-Status (WebDAV)

§

AlreadyReported

208 Already Reported (WebDAV)

§

ImUsed

226 IM Used

§

MultipleChoices

300 Multiple Choices

§

MovedPermanently

301 Moved Permanently

§

Found

302 Found

§

SeeOther

303 See Other

§

NotModified

304 Not Modified

§

UseProxy

305 Use Proxy

§

TemporaryRedirect

307 Temporary Redirect

§

PermanentRedirect

308 Permanent Redirect

§

BadRequest

400 Bad Request

§

Unauthorized

401 Unauthorized

§

PaymentRequired

402 Payment Required

§

Forbidden

403 Forbidden

§

NotFound

404 Not Found

§

MethodNotAllowed

405 Method Not Allowed

§

NotAcceptable

406 Not Acceptable

§

ProxyAuthenticationRequired

407 Proxy Authentication Required

§

RequestTimeout

408 Request Timeout

§

Conflict

409 Conflict

§

Gone

410 Gone

§

LengthRequired

411 Length Required

§

PreconditionFailed

412 Precondition Failed

§

ContentTooLarge

413 Content Too Large

§

UriTooLong

414 URI Too Long

§

UnsupportedMediaType

415 Unsupported Media Type

§

RangeNotSatisfiable

416 Range Not Satisfiable

§

ExpectationFailed

417 Expectation Failed

§

ImATeapot

418 I’m a Teapot (RFC 2324)

§

MisdirectedRequest

421 Misdirected Request

§

UnprocessableContent

422 Unprocessable Content

§

Locked

423 Locked (WebDAV)

§

FailedDependency

424 Failed Dependency (WebDAV)

§

TooEarly

425 Too Early

§

UpgradeRequired

426 Upgrade Required

§

PreconditionRequired

428 Precondition Required

§

TooManyRequests

429 Too Many Requests

§

RequestHeaderFieldsTooLarge

431 Request Header Fields Too Large

§

UnavailableForLegalReasons

451 Unavailable For Legal Reasons

§

InternalServerError

500 Internal Server Error

§

NotImplemented

501 Not Implemented

§

BadGateway

502 Bad Gateway

§

ServiceUnavailable

503 Service Unavailable

§

GatewayTimeout

504 Gateway Timeout

§

HttpVersionNotSupported

505 HTTP Version Not Supported

§

VariantAlsoNegotiates

506 Variant Also Negotiates

§

InsufficientStorage

507 Insufficient Storage (WebDAV)

§

LoopDetected

508 Loop Detected (WebDAV)

§

NotExtended

510 Not Extended

§

NetworkAuthenticationRequired

511 Network Authentication Required

Implementations§

Source§

impl StatusCode

Source

pub const fn as_u16(&self) -> u16

Return the numeric status code.

use api_bones::status::StatusCode;

assert_eq!(StatusCode::Ok.as_u16(), 200);
assert_eq!(StatusCode::NotFound.as_u16(), 404);
Source

pub const fn reason_phrase(&self) -> &'static str

Return the canonical reason phrase.

use api_bones::status::StatusCode;

assert_eq!(StatusCode::Ok.reason_phrase(), "OK");
assert_eq!(StatusCode::NotFound.reason_phrase(), "Not Found");
Source

pub const fn is_informational(&self) -> bool

Returns true for 1xx Informational responses.

Source

pub const fn is_success(&self) -> bool

Returns true for 2xx Successful responses.

use api_bones::status::StatusCode;

assert!(StatusCode::Ok.is_success());
assert!(StatusCode::Created.is_success());
assert!(!StatusCode::BadRequest.is_success());
Source

pub const fn is_redirection(&self) -> bool

Returns true for 3xx Redirection responses.

use api_bones::status::StatusCode;

assert!(StatusCode::MovedPermanently.is_redirection());
assert!(!StatusCode::Ok.is_redirection());
Source

pub const fn is_client_error(&self) -> bool

Returns true for 4xx Client Error responses.

use api_bones::status::StatusCode;

assert!(StatusCode::NotFound.is_client_error());
Source

pub const fn is_server_error(&self) -> bool

Returns true for 5xx Server Error responses.

use api_bones::status::StatusCode;

assert!(StatusCode::InternalServerError.is_server_error());
Source

pub const fn is_error(&self) -> bool

Returns true for either 4xx or 5xx responses.

Trait Implementations§

Source§

impl Clone for StatusCode

Source§

fn clone(&self) -> StatusCode

Returns a duplicate 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

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

impl<'de> Deserialize<'de> for StatusCode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for StatusCode

Source§

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

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

impl From<ErrorCode> for StatusCode

Source§

fn from(code: ErrorCode) -> Self

Converts to this type from the input type.
Source§

impl FromStr for StatusCode

Source§

type Err = UnknownStatusCode

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for StatusCode

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 StatusCode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for StatusCode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<u16> for StatusCode

Source§

type Error = UnknownStatusCode

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

fn try_from(code: u16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for StatusCode

Source§

impl Eq for StatusCode

Source§

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

Source§

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

Source§

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

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> ValidateIp for T
where T: ToString,

Source§

fn validate_ipv4(&self) -> bool

Validates whether the given string is an IP V4
Source§

fn validate_ipv6(&self) -> bool

Validates whether the given string is an IP V6
Source§

fn validate_ip(&self) -> bool

Validates whether the given string is an IP
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,