Skip to content

Commit 0de2956

Browse files
committed
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.
1 parent f61708b commit 0de2956

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/http/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,26 @@ impl<S> MessageHead<S> {
7171
}
7272
}
7373

74+
impl ResponseHead {
75+
/// Converts this head's RawStatus into a StatusCode.
76+
#[inline]
77+
pub fn status(&self) -> StatusCode {
78+
self.subject.status()
79+
}
80+
}
81+
7482
/// The raw status code and reason-phrase.
7583
#[derive(Clone, PartialEq, Debug)]
7684
pub struct RawStatus(pub u16, pub Cow<'static, str>);
7785

86+
impl RawStatus {
87+
/// Converts this into a StatusCode.
88+
#[inline]
89+
pub fn status(&self) -> StatusCode {
90+
StatusCode::from_u16(self.0)
91+
}
92+
}
93+
7894
impl fmt::Display for RawStatus {
7995
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8096
write!(f, "{} {}", self.0, self.1)

0 commit comments

Comments
 (0)