feat(status): add StatusCode::try_from(u16).

This is a temporary function until the `TryFrom` trait stabilizes.

BREAKING CHANGE: Removes the undocumented `from_u16` function. Use
  `StatusCode::try_from` instead.

  Also makes the `status` module private. All imports of
  `hyper::status::StatusCode` should be `hyper::StatusCode`.
This commit is contained in:
Sean McArthur
2017-06-13 09:49:27 -07:00
parent c166268c07
commit f953cafe27
4 changed files with 44 additions and 7 deletions

View File

@@ -160,7 +160,8 @@ impl Http1Transaction for ClientTransaction {
httparse::Status::Complete(len) => {
trace!("Response.try_parse Complete({})", len);
let code = res.code.unwrap();
let reason = match StatusCode::from_u16(code).canonical_reason() {
let status = try!(StatusCode::try_from(code).map_err(|_| ::Error::Status));
let reason = match status.canonical_reason() {
Some(reason) if reason == res.reason.unwrap() => Cow::Borrowed(reason),
_ => Cow::Owned(res.reason.unwrap().to_owned())
};

View File

@@ -89,7 +89,7 @@ impl RawStatus {
/// Converts this into a StatusCode.
#[inline]
pub fn status(&self) -> StatusCode {
StatusCode::from_u16(self.0)
StatusCode::try_from(self.0).unwrap()
}
}