feat(status): impl Into<u16> for StatusCode
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
use std::fmt;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
// shamelessly lifted from Teepee. I tried a few schemes, this really
|
||||
// does seem like the best. Improved scheme to support arbitrary status codes.
|
||||
|
||||
/// An HTTP status code (`status-code` in RFC 7230 et al.).
|
||||
///
|
||||
/// This enum contains all common status codes and an Unregistered
|
||||
@@ -230,6 +227,7 @@ pub enum StatusCode {
|
||||
impl StatusCode {
|
||||
|
||||
#[doc(hidden)]
|
||||
// Not part of public API or API contract. Could disappear.
|
||||
pub fn from_u16(n: u16) -> StatusCode {
|
||||
match n {
|
||||
100 => StatusCode::Continue,
|
||||
@@ -296,8 +294,7 @@ impl StatusCode {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn to_u16(&self) -> u16 {
|
||||
fn to_u16(&self) -> u16 {
|
||||
match *self {
|
||||
StatusCode::Continue => 100,
|
||||
StatusCode::SwitchingProtocols => 101,
|
||||
@@ -553,6 +550,12 @@ impl Default for StatusCode {
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u16> for StatusCode {
|
||||
fn into(self) -> u16 {
|
||||
self.to_u16()
|
||||
}
|
||||
}
|
||||
|
||||
/// The class of an HTTP `status-code`.
|
||||
///
|
||||
/// [RFC 7231, section 6 (Response Status Codes)](https://tools.ietf.org/html/rfc7231#section-6):
|
||||
|
||||
Reference in New Issue
Block a user