Skip to content

Commit

Permalink
feat(status): impl Into<u16> for StatusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Feb 3, 2017
1 parent 027cb71 commit c42f18d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("")))
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c42f18d

Please sign in to comment.