feat(status): impl Into<u16> for StatusCode
This commit is contained in:
		| @@ -82,7 +82,7 @@ impl fmt::Display for RawStatus { | ||||
|  | ||||
| impl From<StatusCode> for RawStatus { | ||||
|     fn from(status: StatusCode) -> RawStatus { | ||||
|         RawStatus(status.to_u16(), Cow::Borrowed(status.canonical_reason().unwrap_or(""))) | ||||
|         RawStatus(status.into(), Cow::Borrowed(status.canonical_reason().unwrap_or(""))) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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