Enum StatusCode

Source
#[repr(u16)]
pub enum StatusCode {
Show 61 variants Continue = 100, SwitchingProtocols = 101, Processing = 102, Ok = 200, Created = 201, Accepted = 202, NonAuthoritativeInformation = 203, NoContent = 204, ResetContent = 205, PartialContent = 206, MultiStatus = 207, AlreadyReported = 208, ImUsed = 226, MultipleChoices = 300, MovedPermanently = 301, Found = 302, SeeOther = 303, NotModified = 304, UseProxy = 305, TemporaryRedirect = 307, PermanentRedirect = 308, BadRequest = 400, Unauthorized = 401, PaymentRequired = 402, Forbidden = 403, NotFound = 404, MethodNotAllowed = 405, NotAcceptable = 406, ProxyAuthenticationRequired = 407, RequestTimeout = 408, Conflict = 409, Gone = 410, LengthRequired = 411, PreconditionFailed = 412, PayloadTooLarge = 413, UriTooLong = 414, UnsupportedMediaType = 415, RangeNotSatisfiable = 416, ExpectationFailed = 417, ImATeapot = 418, MisdirectedRequest = 421, UnprocessableEntity = 422, Locked = 423, FailedDependency = 424, UpgradeRequired = 426, PreconditionRequired = 428, TooManyRequests = 429, RequestHeaderFieldsTooLarge = 431, UnavailableForLegalReasons = 451, InternalServerError = 500, NotImplemented = 501, BadGateway = 502, ServiceUnavailable = 503, GatewayTimeout = 504, HttpVersionNotSupported = 505, VariantAlsoNegotiates = 506, InsufficientStorage = 507, LoopDetected = 508, NotExtended = 510, NetworkAuthenticationRequired = 511, Other(u16),
}
Expand description

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

Constants are provided for known status codes, including those in the IANA HTTP Status Code Registry.

Status code values in the range 100-999 (inclusive) are supported by this type. Values in the range 100-599 are semantically classified by the most significant digit. See StatusCode::is_success, etc. Values above 599 are unclassified but allowed for legacy compatibility, though their use is discouraged. Applications may interpret such values as protocol errors.

§Examples

use axol_http::StatusCode;

assert_eq!(StatusCode::from_u16(200).unwrap(), StatusCode::Ok);
assert_eq!(StatusCode::NotFound.as_u16(), 404);
assert!(StatusCode::Ok.is_success());

Variants§

§

Continue = 100

100 Continue [RFC7231, Section 6.2.1]

§

SwitchingProtocols = 101

101 Switching Protocols [RFC7231, Section 6.2.2]

§

Processing = 102

102 Processing [RFC2518]

§

Ok = 200

§

Created = 201

201 Created [RFC7231, Section 6.3.2]

§

Accepted = 202

202 Accepted [RFC7231, Section 6.3.3]

§

NonAuthoritativeInformation = 203

203 Non-Authoritative Information [RFC7231, Section 6.3.4]

§

NoContent = 204

204 No Content [RFC7231, Section 6.3.5]

§

ResetContent = 205

205 Reset Content [RFC7231, Section 6.3.6]

§

PartialContent = 206

206 Partial Content [RFC7233, Section 4.1]

§

MultiStatus = 207

207 Multi-Status [RFC4918]

§

AlreadyReported = 208

208 Already Reported [RFC5842]

§

ImUsed = 226

226 IM Used [RFC3229]

§

MultipleChoices = 300

300 Multiple Choices [RFC7231, Section 6.4.1]

§

MovedPermanently = 301

301 Moved Permanently [RFC7231, Section 6.4.2]

§

Found = 302

§

SeeOther = 303

303 See Other [RFC7231, Section 6.4.4]

§

NotModified = 304

304 Not Modified [RFC7232, Section 4.1]

§

UseProxy = 305

305 Use Proxy [RFC7231, Section 6.4.5]

§

TemporaryRedirect = 307

307 Temporary Redirect [RFC7231, Section 6.4.7]

§

PermanentRedirect = 308

308 Permanent Redirect [RFC7238]

§

BadRequest = 400

400 Bad Request [RFC7231, Section 6.5.1]

§

Unauthorized = 401

401 Unauthorized [RFC7235, Section 3.1]

§

PaymentRequired = 402

402 Payment Required [RFC7231, Section 6.5.2]

§

Forbidden = 403

403 Forbidden [RFC7231, Section 6.5.3]

§

NotFound = 404

404 Not Found [RFC7231, Section 6.5.4]

§

MethodNotAllowed = 405

405 Method Not Allowed [RFC7231, Section 6.5.5]

§

NotAcceptable = 406

406 Not Acceptable [RFC7231, Section 6.5.6]

§

ProxyAuthenticationRequired = 407

407 Proxy Authentication Required [RFC7235, Section 3.2]

§

RequestTimeout = 408

408 Request Timeout [RFC7231, Section 6.5.7]

§

Conflict = 409

409 Conflict [RFC7231, Section 6.5.8]

§

Gone = 410

§

LengthRequired = 411

411 Length Required [RFC7231, Section 6.5.10]

§

PreconditionFailed = 412

412 Precondition Failed [RFC7232, Section 4.2]

§

PayloadTooLarge = 413

413 Payload Too Large [RFC7231, Section 6.5.11]

§

UriTooLong = 414

414 URI Too Long [RFC7231, Section 6.5.12]

§

UnsupportedMediaType = 415

415 Unsupported Media Type [RFC7231, Section 6.5.13]

§

RangeNotSatisfiable = 416

416 Range Not Satisfiable [RFC7233, Section 4.4]

§

ExpectationFailed = 417

417 Expectation Failed [RFC7231, Section 6.5.14]

§

ImATeapot = 418

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

§

MisdirectedRequest = 421

421 Misdirected Request RFC7540, Section 9.1.2

§

UnprocessableEntity = 422

422 Unprocessable Entity [RFC4918]

§

Locked = 423

423 Locked [RFC4918]

§

FailedDependency = 424

424 Failed Dependency [RFC4918]

§

UpgradeRequired = 426

426 Upgrade Required [RFC7231, Section 6.5.15]

§

PreconditionRequired = 428

428 Precondition Required [RFC6585]

§

TooManyRequests = 429

429 Too Many Requests [RFC6585]

§

RequestHeaderFieldsTooLarge = 431

431 Request Header Fields Too Large [RFC6585]

§

UnavailableForLegalReasons = 451

451 Unavailable For Legal Reasons [RFC7725]

§

InternalServerError = 500

500 Internal Server Error [RFC7231, Section 6.6.1]

§

NotImplemented = 501

501 Not Implemented [RFC7231, Section 6.6.2]

§

BadGateway = 502

502 Bad Gateway [RFC7231, Section 6.6.3]

§

ServiceUnavailable = 503

503 Service Unavailable [RFC7231, Section 6.6.4]

§

GatewayTimeout = 504

504 Gateway Timeout [RFC7231, Section 6.6.5]

§

HttpVersionNotSupported = 505

505 HTTP Version Not Supported [RFC7231, Section 6.6.6]

§

VariantAlsoNegotiates = 506

506 Variant Also Negotiates [RFC2295]

§

InsufficientStorage = 507

507 Insufficient Storage [RFC4918]

§

LoopDetected = 508

508 Loop Detected [RFC5842]

§

NotExtended = 510

510 Not Extended [RFC2774]

§

NetworkAuthenticationRequired = 511

511 Network Authentication Required [RFC6585]

§

Other(u16)

An unknown (invalid) status code. It is a logic error that will do unexpected things if this is initialized to a valid status code.

Implementations§

Source§

impl StatusCode

Source

pub fn from_repr(discriminant: u16) -> Option<StatusCode>

Try to create Self from the raw representation

Source§

impl StatusCode

Source

pub fn from_u16(value: u16) -> Result<Self, StatusCodeError>

Converts a u16 to a status code.

The function validates the correctness of the supplied u16. It must be greater or equal to 100 and less than 1000.

§Example
use axol_http::StatusCode;

let ok = StatusCode::from_u16(200).unwrap();
assert!(matches!(ok, StatusCode::Ok);

let err = StatusCode::from_u16(99);
assert!(err.is_err());
Source

pub fn as_u16(&self) -> u16

Returns the u16 corresponding to this StatusCode.

§Note

This is the same as the From<StatusCode> implementation, but included as an inherent method because that implementation doesn’t appear in rustdocs, as well as a way to force the type instead of relying on inference.

§Example
let status = axol_http::StatusCode::Ok;
assert_eq!(status.as_u16(), 200);
Source

pub fn as_str(&self) -> &'static str

Returns a &str representation of the StatusCode

The return value only includes a numerical representation of the status code. The canonical reason is not included.

§Example
let status = axol_http::StatusCode::Ok;
assert_eq!(status.as_str(), "200");
Source

pub fn canonical_reason(&self) -> &'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 and HTTP/3.0 the reason phrase is abolished from transmission, and so this canonical reason phrase really is the only reason phrase you’ll find.

This is empty for Other or invalid status codes.

§Example
let status = axol_http::StatusCode::OK;
assert_eq!(status.canonical_reason(), "OK");
Source

pub fn is_informational(&self) -> bool

Check if status is within 100-199.

Source

pub fn is_success(&self) -> bool

Check if status is within 200-299.

Source

pub fn is_redirection(&self) -> bool

Check if status is within 300-399.

Source

pub fn is_client_error(&self) -> bool

Check if status is within 400-499.

Source

pub fn is_server_error(&self) -> bool

Check if status is within 500-599.

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

Source§

fn default() -> StatusCode

Returns the “default value” for a type. 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 EnumProperty for StatusCode

Source§

fn get_str(&self, prop: &str) -> Option<&'static str>

Source§

fn get_int(&self, _prop: &str) -> Option<usize>

Source§

fn get_bool(&self, _prop: &str) -> Option<bool>

Source§

impl From<StatusCode> for StatusCode

Source§

fn from(value: StatusCode) -> Self

Converts to this type from the input type.
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 Into<StatusCode> for StatusCode

Source§

fn into(self) -> StatusCode

Converts this type into the (usually inferred) input type.
Source§

impl Into<u16> for StatusCode

Source§

fn into(self) -> u16

Converts this type into the (usually inferred) input type.
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,

Restrict a value to a certain interval. 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 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<u16> for StatusCode

Source§

type Error = StatusCodeError

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

fn try_from(value: 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<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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext 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> Same for T

Source§

type Output = T

Should always be Self
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.