Skip to content

Commit

Permalink
Merge pull request #73 from rmja/status-helpers
Browse files Browse the repository at this point in the history
Move the Status helpers to StatusCode
  • Loading branch information
rmja committed May 21, 2024
2 parents 12c5ab7 + 56d253f commit 87ae6c5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,30 +449,25 @@ pub enum Status {
Unknown = 0,
}

impl Status {
impl StatusCode {
pub fn is_informational(&self) -> bool {
let status = *self as u16;
(100..=199).contains(&status)
(100..=199).contains(&self.0)
}

pub fn is_successful(&self) -> bool {
let status = *self as u16;
(200..=299).contains(&status)
(200..=299).contains(&self.0)
}

pub fn is_redirection(&self) -> bool {
let status = *self as u16;
(300..=399).contains(&status)
(300..=399).contains(&self.0)
}

pub fn is_client_error(&self) -> bool {
let status = *self as u16;
(400..=499).contains(&status)
(400..=499).contains(&self.0)
}

pub fn is_server_error(&self) -> bool {
let status = *self as u16;
(500..=599).contains(&status)
(500..=599).contains(&self.0)
}
}

Expand Down Expand Up @@ -816,6 +811,9 @@ mod tests {
assert_eq!(StatusCode(0), StatusCode(0));
assert_eq!(StatusCode(987), StatusCode(987));
assert_ne!(StatusCode(123), StatusCode(321));

let status: Status = StatusCode(200).into();
assert_eq!(Status::Ok, status);
}

#[test]
Expand Down

0 comments on commit 87ae6c5

Please sign in to comment.