feat(status): impl Into<u16> for StatusCode

This commit is contained in:
Sean McArthur
2017-02-02 17:02:35 -08:00
parent 027cb71b7b
commit c42f18db05
2 changed files with 9 additions and 6 deletions

View File

@@ -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("")))
}
}

View File

@@ -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):