[−][src]Enum hyper::status::StatusClass
The class of an HTTP status-code
.
RFC 7231, section 6 (Response Status Codes):
The first digit of the status-code defines the class of response. The last two digits do not have any categorization role.
And:
HTTP status codes are extensible. HTTP clients are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, a client MUST understand the class of any status code, as indicated by the first digit, and treat an unrecognized status code as being equivalent to the x00 status code of that class, with the exception that a recipient MUST NOT cache a response with an unrecognized status code.
For example, if an unrecognized status code of 471 is received by a client, the client can assume that there was something wrong with its request and treat the response as if it had received a 400 (Bad Request) status code. The response message will usually contain a representation that explains the status.
This can be used in cases where a status code’s meaning is unknown, also, to get the appropriate category of status.
Variants
Informational
1xx (Informational): The request was received, continuing process
Success
2xx (Success): The request was successfully received, understood, and accepted
Redirection
3xx (Redirection): Further action needs to be taken in order to complete the request
ClientError
4xx (Client Error): The request contains bad syntax or cannot be fulfilled
ServerError
5xx (Server Error): The server failed to fulfill an apparently valid request
NoClass
A status code lower than 100 or higher than 599. These codes do no belong to any class.
Methods
impl StatusClass
[src]
impl StatusClass
pub fn default_code(&self) -> StatusCode
[src]
pub fn default_code(&self) -> StatusCode
Get the default status code for the class.
This produces the x00 status code; thus, for ClientError
(4xx), for
example, this will produce BadRequest
(400):
assert_eq!(ClientError.default_code(), BadRequest);
The use for this is outlined in RFC 7231, section 6 (Response Status Codes):
HTTP status codes are extensible. HTTP clients are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, a client MUST understand the class of any status code, as indicated by the first digit, and treat an unrecognized status code as being equivalent to the x00 status code of that class, with the exception that a recipient MUST NOT cache a response with an unrecognized status code.
For example, if an unrecognized status code of 471 is received by a client, the client can assume that there was something wrong with its request and treat the response as if it had received a 400 (Bad Request) status code. The response message will usually contain a representation that explains the status.
This is demonstrated thusly:
// Suppose we have received this status code. // You will never directly create an unregistered status code. let status = Unregistered(471); // Uh oh! Don’t know what to do with it. // Let’s fall back to the default: let status = status.class().default_code(); // And look! That is 400 Bad Request. assert_eq!(status, BadRequest); // So now let’s treat it as that.
All status codes that do not map to an existing status class are matched
by a NoClass
, variant that resolves to 200 (Ok) as default code.
This is a common handling for unknown status codes in major browsers.
Trait Implementations
impl PartialOrd<StatusClass> for StatusClass
[src]
impl PartialOrd<StatusClass> for StatusClass
fn partial_cmp(&self, other: &StatusClass) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &StatusClass) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for StatusClass
[src]
impl Ord for StatusClass
fn cmp(&self, other: &StatusClass) -> Ordering
[src]
fn cmp(&self, other: &StatusClass) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl PartialEq<StatusClass> for StatusClass
[src]
impl PartialEq<StatusClass> for StatusClass
fn eq(&self, other: &StatusClass) -> bool
[src]
fn eq(&self, other: &StatusClass) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Clone for StatusClass
[src]
impl Clone for StatusClass
fn clone(&self) -> StatusClass
[src]
fn clone(&self) -> StatusClass
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for StatusClass
[src]
impl Copy for StatusClass
impl Eq for StatusClass
[src]
impl Eq for StatusClass
impl Debug for StatusClass
[src]
impl Debug for StatusClass
Auto Trait Implementations
impl Send for StatusClass
impl Send for StatusClass
impl Sync for StatusClass
impl Sync for StatusClass
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T> Typeable for T where
T: Any,
[src]
impl<T> Typeable for T where
T: Any,