Skip to main content

StatusCode

Enum StatusCode 

Source
pub enum StatusCode {
Show 63 variants CONTINUE = 100, SWITCHING_PROTOCOLS = 101, PROCESSING = 102, EARLY_HINTS = 103, OK = 200, CREATED = 201, ACCEPTED = 202, NON_AUTHORITATIVE_INFORMATION = 203, NO_CONTENT = 204, RESET_CONTENT = 205, PARTIAL_CONTENT = 206, MULTI_STATUS = 207, ALREADY_REPORTED = 208, IM_USED = 226, MULTIPLE_CHOICES = 300, MOVED_PERMANENTLY = 301, FOUND = 302, SEE_OTHER = 303, NOT_MODIFIED = 304, USE_PROXY = 305, TEMPORARY_REDIRECT = 307, PERMANENT_REDIRECT = 308, BAD_REQUEST = 400, UNAUTHORIZED = 401, PAYMENT_REQUIRED = 402, FORBIDDEN = 403, NOT_FOUND = 404, METHOD_NOT_ALLOWED = 405, NOT_ACCEPTABLE = 406, PROXY_AUTHENTICATION_REQUIRED = 407, REQUEST_TIMEOUT = 408, CONFLICT = 409, GONE = 410, LENGTH_REQUIRED = 411, PRECONDITION_FAILED = 412, PAYLOAD_TOO_LARGE = 413, URI_TOO_LONG = 414, UNSUPPORTED_MEDIA_TYPE = 415, RANGE_NOT_SATISFIABLE = 416, EXPECTATION_FAILED = 417, IM_A_TEAPOT = 418, MISDIRECTED_REQUEST = 421, UNPROCESSABLE_ENTITY = 422, LOCKED = 423, FAILED_DEPENDENCY = 424, TOO_EARLY = 425, UPGRADE_REQUIRED = 426, PRECONDITION_REQUIRED = 428, TOO_MANY_REQUESTS = 429, REQUEST_HEADER_FIELDS_TOO_LARGE = 431, UNAVAILABLE_FOR_LEGAL_REASONS = 451, INTERNAL_SERVER_ERROR = 500, NOT_IMPLEMENTED = 501, BAD_GATEWAY = 502, SERVICE_UNAVAILABLE = 503, GATEWAY_TIMEOUT = 504, HTTP_VERSION_NOT_SUPPORTED = 505, VARIANT_ALSO_NEGOTIATES = 506, INSUFFICIENT_STORAGE = 507, LOOP_DETECTED = 508, NOT_EXTENDED = 510, NETWORK_AUTHENTICATION_REQUIRED = 511, UNKNOWN = 0,
}
Expand description

Represents HTTP status codes.

This enum includes the most common HTTP status codes and provides methods to check status code categories, convert between numeric and string representations, and perform other common operations.

Variants§

§

CONTINUE = 100

§

SWITCHING_PROTOCOLS = 101

§

PROCESSING = 102

§

EARLY_HINTS = 103

§

OK = 200

§

CREATED = 201

§

ACCEPTED = 202

§

NON_AUTHORITATIVE_INFORMATION = 203

§

NO_CONTENT = 204

§

RESET_CONTENT = 205

§

PARTIAL_CONTENT = 206

§

MULTI_STATUS = 207

§

ALREADY_REPORTED = 208

§

IM_USED = 226

§

MULTIPLE_CHOICES = 300

§

MOVED_PERMANENTLY = 301

§

FOUND = 302

§

SEE_OTHER = 303

§

NOT_MODIFIED = 304

§

USE_PROXY = 305

§

TEMPORARY_REDIRECT = 307

§

PERMANENT_REDIRECT = 308

§

BAD_REQUEST = 400

§

UNAUTHORIZED = 401

§

PAYMENT_REQUIRED = 402

§

FORBIDDEN = 403

§

NOT_FOUND = 404

§

METHOD_NOT_ALLOWED = 405

§

NOT_ACCEPTABLE = 406

§

PROXY_AUTHENTICATION_REQUIRED = 407

§

REQUEST_TIMEOUT = 408

§

CONFLICT = 409

§

GONE = 410

§

LENGTH_REQUIRED = 411

§

PRECONDITION_FAILED = 412

§

PAYLOAD_TOO_LARGE = 413

§

URI_TOO_LONG = 414

§

UNSUPPORTED_MEDIA_TYPE = 415

§

RANGE_NOT_SATISFIABLE = 416

§

EXPECTATION_FAILED = 417

§

IM_A_TEAPOT = 418

§

MISDIRECTED_REQUEST = 421

§

UNPROCESSABLE_ENTITY = 422

§

LOCKED = 423

§

FAILED_DEPENDENCY = 424

§

TOO_EARLY = 425

§

UPGRADE_REQUIRED = 426

§

PRECONDITION_REQUIRED = 428

§

TOO_MANY_REQUESTS = 429

§

REQUEST_HEADER_FIELDS_TOO_LARGE = 431

§

INTERNAL_SERVER_ERROR = 500

§

NOT_IMPLEMENTED = 501

§

BAD_GATEWAY = 502

§

SERVICE_UNAVAILABLE = 503

§

GATEWAY_TIMEOUT = 504

§

HTTP_VERSION_NOT_SUPPORTED = 505

§

VARIANT_ALSO_NEGOTIATES = 506

§

INSUFFICIENT_STORAGE = 507

§

LOOP_DETECTED = 508

§

NOT_EXTENDED = 510

§

NETWORK_AUTHENTICATION_REQUIRED = 511

§

UNKNOWN = 0

Implementations§

Source§

impl StatusCode

Source

pub fn as_u16(&self) -> u16

Returns the numeric value of the status code.

§Returns

The u16 value of this status code.

§Examples
use crate::http_value::StatusCode;
let code = StatusCode::OK;
assert_eq!(code.as_u16(), 200);
Source

pub fn to_string(&self) -> String

Returns a string representation of the status code.

§Returns

A string containing both the numeric code and its reason phrase.

§Examples
use crate::http_value::StatusCode;
let code = StatusCode::OK;
assert_eq!(code.to_string(), "200 OK");
Source

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

Gets only the reason phrase part of the status code.

§Returns

The reason phrase part of the status code.

Source

pub fn from_u16(code: u16) -> StatusCode

Creates a status code from a u16 value.

§Arguments
  • code - The numeric status code.
§Returns

The corresponding StatusCode enum value, or UNKNOWN for unsupported codes.

Source

pub fn from_string(code: &str) -> StatusCode

Creates a status code from a string representation.

§Arguments
  • code - The string representation of the status code.
§Returns

The corresponding StatusCode enum value, or UNKNOWN if not recognized.

Source

pub fn is_informational(&self) -> bool

Checks if the status code is informational (1xx).

§Returns

true if the status code is in the 1xx range, false otherwise.

Source

pub fn is_success(&self) -> bool

Checks if the status code indicates success (2xx).

§Returns

true if the status code is in the 2xx range, false otherwise.

Source

pub fn is_redirection(&self) -> bool

Checks if the status code indicates redirection (3xx).

§Returns

true if the status code is in the 3xx range, false otherwise.

Source

pub fn is_client_error(&self) -> bool

Checks if the status code indicates a client error (4xx).

§Returns

true if the status code is in the 4xx range, false otherwise.

Source

pub fn is_server_error(&self) -> bool

Checks if the status code indicates a server error (5xx).

§Returns

true if the status code is in the 5xx range, false otherwise.

Source

pub fn is_error(&self) -> bool

Checks if the status code indicates an error (4xx or 5xx).

§Returns

true if the status code is in the 4xx or 5xx range, false otherwise.

Source

pub fn is_not_found(&self) -> bool

Checks if the status code indicates that the resource was not found (404).

§Returns

true if the status code is 404, false otherwise.

Source

pub fn is_ok(&self) -> bool

Checks if the status code indicates a successful response (200 OK).

§Returns

true if the status code is 200, false otherwise.

Source

pub fn is_no_content(&self) -> bool

Checks if the status code indicates that the content should be omitted (204 No Content).

§Returns

true if the status code is 204, false otherwise.

Source

pub fn is_created(&self) -> bool

Checks if the status code indicates that the requested resource was created (201 Created).

§Returns

true if the status code is 201, false otherwise.

Source

pub fn is_unauthorized(&self) -> bool

Checks if the status code indicates that the client is not authorized (401 Unauthorized).

§Returns

true if the status code is 401, false otherwise.

Trait Implementations§

Source§

impl Clone for StatusCode

Source§

fn clone(&self) -> StatusCode

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 StatusCode

Source§

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

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

impl Display for StatusCode

Source§

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

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

impl Eq for StatusCode

Source§

impl From<&HttpError> for StatusCode

Convert an HttpError into the most appropriate HTTP StatusCode.

This is useful when you need to map an HttpError to a response status code for error responses.

Source§

fn from(err: &HttpError) -> StatusCode

Converts to this type from the input type.
Source§

impl From<&str> for StatusCode

Source§

fn from(code: &str) -> StatusCode

Converts to this type from the input type.
Source§

impl From<String> for StatusCode

Source§

fn from(code: String) -> StatusCode

Converts to this type from the input type.
Source§

impl From<u16> for StatusCode

Source§

fn from(code: u16) -> StatusCode

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

Source§

fn eq(&self, other: &StatusCode) -> 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 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

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented 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> ParamValue for T
where T: Any + Clone + Send + Sync + 'static,

Source§

fn clone_box(&self) -> Box<dyn ParamValue>

Clones this value and returns it as a boxed ParamValue. Read more
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the underlying value as Any. Read more
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns a mutable reference to the underlying value as Any. Read more
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 = !

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more