http_type

Enum StatusCode

Source
pub enum StatusCode {
    Ok,
    Created,
    NoContent,
    BadRequest,
    Unauthorized,
    Forbidden,
    NotFound,
    InternalServerError,
    NotImplemented,
    BadGateway,
    Unknown,
}
Expand description

Enumeration of HTTP status codes representing various HTTP response statuses

This enum includes common HTTP status codes that cover successful requests, client errors, and server errors. Each variant represents a specific HTTP status code.

§Variants

  • Ok: HTTP 200, indicates that the request was successful and the server has successfully processed it.
  • Created: HTTP 201, indicates that the request was successful and the server has created a new resource.
  • NoContent: HTTP 204, indicates that the request was successful but no content is returned.
  • BadRequest: HTTP 400, indicates that the request is invalid or malformed and the server cannot understand it.
  • Unauthorized: HTTP 401, indicates that the request is unauthorized and requires authentication.
  • Forbidden: HTTP 403, indicates that the server understands the request but refuses to authorize it, usually due to insufficient permissions.
  • NotFound: HTTP 404, indicates that the server cannot find the requested resource.
  • InternalServerError: HTTP 500, indicates that the server encountered an internal error and cannot process the request.
  • NotImplemented: HTTP 501, indicates that the server does not support the functionality required to fulfill the request.
  • BadGateway: HTTP 502, indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server.
  • Unknown: Represents an unknown status code, typically used when the status code is not recognized or is undefined.

Variants§

§

Ok

200 OK

§

Created

201 Created

§

NoContent

204 No Content

§

BadRequest

400 Bad Request

§

Unauthorized

401 Unauthorized

§

Forbidden

403 Forbidden

§

NotFound

404 Not Found

§

InternalServerError

500 Internal Server Error

§

NotImplemented

501 Not Implemented

§

BadGateway

502 Bad Gateway

§

Unknown

Unknown status code

Implementations§

Source§

impl StatusCode

The StatusCode enum represents the HTTP status codes.

It maps common HTTP status codes to their respective meanings. It provides methods to retrieve the corresponding numeric code as well as the associated status text. Additionally, it implements conversion from a string representation of the status code.

§Variants

  • Ok: HTTP status 200, indicating a successful request.
  • Created: HTTP status 201, indicating that the request was successful and resulted in a resource creation.
  • NoContent: HTTP status 204, indicating that the request was successful, but there is no content to return.
  • BadRequest: HTTP status 400, indicating a bad request, often due to incorrect syntax or invalid data.
  • Unauthorized: HTTP status 401, indicating that authentication is required and has failed or not been provided.
  • Forbidden: HTTP status 403, indicating that the server understands the request but refuses to authorize it.
  • NotFound: HTTP status 404, indicating that the requested resource could not be found.
  • InternalServerError: HTTP status 500, indicating that the server encountered an internal error.
  • NotImplemented: HTTP status 501, indicating that the server does not support the functionality required to fulfill the request.
  • BadGateway: HTTP status 502, indicating that the server, while acting as a gateway or proxy, received an invalid response from an upstream server.
  • Unknown: A default variant for unrecognized or undefined status codes.
Source

pub fn code(&self) -> u16

Returns the numeric HTTP status code associated with this status code variant.

This method returns the corresponding HTTP numeric status code based on the StatusCode variant. For example:

  • Self::Ok returns 200.
  • Self::BadRequest returns 400.
  • Self::Unknown returns 0 (the default for unrecognized status codes).
§Parameters
  • &self: A reference to the StatusCode enum instance. This represents the specific variant of the StatusCode enum that the method is called on.
§Return Value
  • u16: The numeric HTTP status code associated with the StatusCode variant. For example:
    • Self::Ok returns 200.
    • Self::BadRequest returns 400.
    • Self::Unknown returns 0.
Source

pub fn phrase(code: usize) -> String

Converts an HTTP status code to its corresponding textual description.

This method matches a given numeric HTTP status code and returns the corresponding textual representation defined in the StatusCode enum.

§Parameters
  • code: A usize representing the HTTP status code to convert.
§Return Value
  • String: A string representing the textual description of the HTTP status code. For example:
    • 200 returns "OK".
    • 404 returns "Not Found".
    • Unrecognized codes return "Unknown".
Source

pub fn same(&self, code_str: &str) -> bool

Trait Implementations§

Source§

impl Default for StatusCode

Source§

fn default() -> Self

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

Source§

type Err = ()

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

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

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

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> 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> 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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T