From c42f18db05e47fc24e8a8ece76cbc782b7558e8b Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Thu, 2 Feb 2017 17:02:35 -0800 Subject: [PATCH] feat(status): impl Into for StatusCode --- src/http/mod.rs | 2 +- src/status.rs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/http/mod.rs b/src/http/mod.rs index 13c5011984..4a68812733 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -82,7 +82,7 @@ impl fmt::Display for RawStatus { impl From 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(""))) } } diff --git a/src/status.rs b/src/status.rs index 8a49bb7300..71d40b5c3c 100644 --- a/src/status.rs +++ b/src/status.rs @@ -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 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):