refactor(http): add status() methods to RawStatus and ResponseHead

This lets us convert RawStatus to StatusCode in Response without having to address the tuple index
directly.
This commit is contained in:
Nick Gonzales
2017-05-01 12:00:11 -06:00
parent f61708ba81
commit 0de295670f

View File

@@ -71,10 +71,26 @@ impl<S> MessageHead<S> {
}
}
impl ResponseHead {
/// Converts this head's RawStatus into a StatusCode.
#[inline]
pub fn status(&self) -> StatusCode {
self.subject.status()
}
}
/// The raw status code and reason-phrase.
#[derive(Clone, PartialEq, Debug)]
pub struct RawStatus(pub u16, pub Cow<'static, str>);
impl RawStatus {
/// Converts this into a StatusCode.
#[inline]
pub fn status(&self) -> StatusCode {
StatusCode::from_u16(self.0)
}
}
impl fmt::Display for RawStatus {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} {}", self.0, self.1)