Struct json_api::value::StatusCode
[−]
[src]
pub struct StatusCode(_);
An HTTP status code (status-code
in RFC 7230 et al.).
This type contains constructor functions for all common status codes.
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.
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).
Examples
use http::StatusCode; assert_eq!(StatusCode::from_u16(200).unwrap(), StatusCode::OK); assert_eq!(StatusCode::NOT_FOUND.as_u16(), 404); assert!(StatusCode::OK.is_success());
Methods
impl StatusCode
[src]
fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode>
[src][−]
Converts a u16 to a status code.
The function validates the correctness of the supplied u16. It must be greater or equal to 100 but less than 600.
Example
use http::StatusCode; let ok = StatusCode::from_u16(200).unwrap(); assert_eq!(ok, StatusCode::OK); let err = StatusCode::from_u16(99); assert!(err.is_err());
fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>
[src][−]
Converts a &[u8] to a status code
fn as_u16(&self) -> u16
[src][−]
Returns the u16
corresponding to this StatusCode
.
Example
let status = http::StatusCode::OK; assert_eq!(status.as_u16(), 200);
fn is_informational(&self) -> bool
[src][−]
Check if status is within 100-199.
fn is_success(&self) -> bool
[src][−]
Check if status is within 200-299.
fn is_redirection(&self) -> bool
[src][−]
Check if status is within 300-399.
fn is_client_error(&self) -> bool
[src][−]
Check if status is within 400-499.
fn is_server_error(&self) -> bool
[src][−]
Check if status is within 500-599.
impl StatusCode
[src]
const CONTINUE: StatusCode
[−]
CONTINUE: StatusCode = StatusCode(100)
const SWITCHING_PROTOCOLS: StatusCode
[−]
SWITCHING_PROTOCOLS: StatusCode = StatusCode(101)
const PROCESSING: StatusCode
[−]
PROCESSING: StatusCode = StatusCode(102)
const OK: StatusCode
[−]
OK: StatusCode = StatusCode(200)
const CREATED: StatusCode
[−]
CREATED: StatusCode = StatusCode(201)
const ACCEPTED: StatusCode
[−]
ACCEPTED: StatusCode = StatusCode(202)
const NON_AUTHORITATIVE_INFORMATION: StatusCode
[−]
NON_AUTHORITATIVE_INFORMATION: StatusCode = StatusCode(203)
const NO_CONTENT: StatusCode
[−]
NO_CONTENT: StatusCode = StatusCode(204)
const RESET_CONTENT: StatusCode
[−]
RESET_CONTENT: StatusCode = StatusCode(205)
const PARTIAL_CONTENT: StatusCode
[−]
PARTIAL_CONTENT: StatusCode = StatusCode(206)
const MULTI_STATUS: StatusCode
[−]
MULTI_STATUS: StatusCode = StatusCode(207)
const ALREADY_REPORTED: StatusCode
[−]
ALREADY_REPORTED: StatusCode = StatusCode(208)
const IM_USED: StatusCode
[−]
IM_USED: StatusCode = StatusCode(226)
const MULTIPLE_CHOICES: StatusCode
[−]
MULTIPLE_CHOICES: StatusCode = StatusCode(300)
const MOVED_PERMANENTLY: StatusCode
[−]
MOVED_PERMANENTLY: StatusCode = StatusCode(301)
const FOUND: StatusCode
[−]
FOUND: StatusCode = StatusCode(302)
const SEE_OTHER: StatusCode
[−]
SEE_OTHER: StatusCode = StatusCode(303)
const NOT_MODIFIED: StatusCode
[−]
NOT_MODIFIED: StatusCode = StatusCode(304)
const USE_PROXY: StatusCode
[−]
USE_PROXY: StatusCode = StatusCode(305)
const TEMPORARY_REDIRECT: StatusCode
[−]
TEMPORARY_REDIRECT: StatusCode = StatusCode(307)
const PERMANENT_REDIRECT: StatusCode
[−]
PERMANENT_REDIRECT: StatusCode = StatusCode(308)
const BAD_REQUEST: StatusCode
[−]
BAD_REQUEST: StatusCode = StatusCode(400)
const UNAUTHORIZED: StatusCode
[−]
UNAUTHORIZED: StatusCode = StatusCode(401)
const PAYMENT_REQUIRED: StatusCode
[−]
PAYMENT_REQUIRED: StatusCode = StatusCode(402)
const FORBIDDEN: StatusCode
[−]
FORBIDDEN: StatusCode = StatusCode(403)
const NOT_FOUND: StatusCode
[−]
NOT_FOUND: StatusCode = StatusCode(404)
const METHOD_NOT_ALLOWED: StatusCode
[−]
METHOD_NOT_ALLOWED: StatusCode = StatusCode(405)
const NOT_ACCEPTABLE: StatusCode
[−]
NOT_ACCEPTABLE: StatusCode = StatusCode(406)
const PROXY_AUTHENTICATION_REQUIRED: StatusCode
[−]
PROXY_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(407)
const REQUEST_TIMEOUT: StatusCode
[−]
REQUEST_TIMEOUT: StatusCode = StatusCode(408)
const CONFLICT: StatusCode
[−]
CONFLICT: StatusCode = StatusCode(409)
const GONE: StatusCode
[−]
GONE: StatusCode = StatusCode(410)
const LENGTH_REQUIRED: StatusCode
[−]
LENGTH_REQUIRED: StatusCode = StatusCode(411)
const PRECONDITION_FAILED: StatusCode
[−]
PRECONDITION_FAILED: StatusCode = StatusCode(412)
const PAYLOAD_TOO_LARGE: StatusCode
[−]
PAYLOAD_TOO_LARGE: StatusCode = StatusCode(413)
const URI_TOO_LONG: StatusCode
[−]
URI_TOO_LONG: StatusCode = StatusCode(414)
const UNSUPPORTED_MEDIA_TYPE: StatusCode
[−]
UNSUPPORTED_MEDIA_TYPE: StatusCode = StatusCode(415)
const RANGE_NOT_SATISFIABLE: StatusCode
[−]
RANGE_NOT_SATISFIABLE: StatusCode = StatusCode(416)
const EXPECTATION_FAILED: StatusCode
[−]
EXPECTATION_FAILED: StatusCode = StatusCode(417)
const IM_A_TEAPOT: StatusCode
[−]
IM_A_TEAPOT: StatusCode = StatusCode(418)
const MISDIRECTED_REQUEST: StatusCode
[−]
MISDIRECTED_REQUEST: StatusCode = StatusCode(421)
const UNPROCESSABLE_ENTITY: StatusCode
[−]
UNPROCESSABLE_ENTITY: StatusCode = StatusCode(422)
const LOCKED: StatusCode
[−]
LOCKED: StatusCode = StatusCode(423)
const FAILED_DEPENDENCY: StatusCode
[−]
FAILED_DEPENDENCY: StatusCode = StatusCode(424)
const UPGRADE_REQUIRED: StatusCode
[−]
UPGRADE_REQUIRED: StatusCode = StatusCode(426)
const PRECONDITION_REQUIRED: StatusCode
[−]
PRECONDITION_REQUIRED: StatusCode = StatusCode(428)
const TOO_MANY_REQUESTS: StatusCode
[−]
TOO_MANY_REQUESTS: StatusCode = StatusCode(429)
const REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode
[−]
REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode = StatusCode(431)
const UNAVAILABLE_FOR_LEGAL_REASONS: StatusCode
[−]
UNAVAILABLE_FOR_LEGAL_REASONS: StatusCode = StatusCode(451)
const INTERNAL_SERVER_ERROR: StatusCode
[−]
INTERNAL_SERVER_ERROR: StatusCode = StatusCode(500)
const NOT_IMPLEMENTED: StatusCode
[−]
NOT_IMPLEMENTED: StatusCode = StatusCode(501)
const BAD_GATEWAY: StatusCode
[−]
BAD_GATEWAY: StatusCode = StatusCode(502)
const SERVICE_UNAVAILABLE: StatusCode
[−]
SERVICE_UNAVAILABLE: StatusCode = StatusCode(503)
const GATEWAY_TIMEOUT: StatusCode
[−]
GATEWAY_TIMEOUT: StatusCode = StatusCode(504)
const HTTP_VERSION_NOT_SUPPORTED: StatusCode
[−]
HTTP_VERSION_NOT_SUPPORTED: StatusCode = StatusCode(505)
const VARIANT_ALSO_NEGOTIATES: StatusCode
[−]
VARIANT_ALSO_NEGOTIATES: StatusCode = StatusCode(506)
const INSUFFICIENT_STORAGE: StatusCode
[−]
INSUFFICIENT_STORAGE: StatusCode = StatusCode(507)
const LOOP_DETECTED: StatusCode
[−]
LOOP_DETECTED: StatusCode = StatusCode(508)
const NOT_EXTENDED: StatusCode
[−]
NOT_EXTENDED: StatusCode = StatusCode(510)
const NETWORK_AUTHENTICATION_REQUIRED: StatusCode
[−]
NETWORK_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(511)
fn canonical_reason(&self) -> Option<&'static str>
[src][−]
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.
impl StatusCode
[src]
fn as_str(&self) -> &str
[src][−]
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.
Trait Implementations
impl Ord for StatusCode
[src]
fn cmp(&self, __arg_0: &StatusCode) -> Ordering
[src][−]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src][−]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src][−]
Compares and returns the minimum of two values. Read more
impl Hash for StatusCode
[src]
fn hash<__H>(&self, __arg_0: &mut __H) where
__H: Hasher,
[src][−]
__H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src][−]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Copy for StatusCode
[src]
impl Clone for StatusCode
[src]
fn clone(&self) -> StatusCode
[src][−]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src][−]
Performs copy-assignment from source
. Read more
impl PartialEq<StatusCode> for StatusCode
[src]
fn eq(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests for !=
.
impl FromStr for StatusCode
[src]
type Err = InvalidStatusCode
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>
[src][−]
Parses a string s
to return a value of this type. Read more
impl Debug for StatusCode
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src][−]
Formats the value using the given formatter.
impl Default for StatusCode
[src]
fn default() -> StatusCode
[src][−]
Returns the "default value" for a type. Read more
impl Eq for StatusCode
[src]
impl<'a> HttpTryFrom<&'a str> for StatusCode
[src]
type Error = InvalidStatusCode
fn try_from(
t: &'a str
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a str>>::Error>
[src]
t: &'a str
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a str>>::Error>
impl HttpTryFrom<StatusCode> for StatusCode
[src]
type Error = Error
fn try_from(
t: StatusCode
) -> Result<StatusCode, <StatusCode as HttpTryFrom<StatusCode>>::Error>
[src]
t: StatusCode
) -> Result<StatusCode, <StatusCode as HttpTryFrom<StatusCode>>::Error>
impl<'a> HttpTryFrom<&'a [u8]> for StatusCode
[src]
type Error = InvalidStatusCode
fn try_from(
t: &'a [u8]
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a [u8]>>::Error>
[src]
t: &'a [u8]
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a [u8]>>::Error>
impl HttpTryFrom<u16> for StatusCode
[src]
type Error = InvalidStatusCode
fn try_from(
t: u16
) -> Result<StatusCode, <StatusCode as HttpTryFrom<u16>>::Error>
[src]
t: u16
) -> Result<StatusCode, <StatusCode as HttpTryFrom<u16>>::Error>
impl Display for StatusCode
[src]
Formats the status code, including the canonical reason.
assert_eq!(format!("{}", StatusCode::OK), "200 OK");
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src][−]
Formats the value using the given formatter. Read more
impl PartialOrd<StatusCode> for StatusCode
[src]
fn partial_cmp(&self, __arg_0: &StatusCode) -> Option<Ordering>
[src][−]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &StatusCode) -> bool
[src][−]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more