Skip to content

Commit

Permalink
feat: Implement is_error() for ResponseType
Browse files Browse the repository at this point in the history
  • Loading branch information
martindisch committed Jan 22, 2025
1 parent 4a45bd5 commit 41e3bea
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ pub enum ResponseType {
UnKnown,
}

impl ResponseType {
pub fn is_error(&self) -> bool {
MessageClass::Response(*self)
>= MessageClass::Response(ResponseType::BadRequest)
}
}

/// The message types.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MessageType {
Expand Down Expand Up @@ -418,4 +425,13 @@ mod test {
h.set_type(MessageType::Reset);
assert_eq!(MessageType::Reset, h.get_type());
}

#[test]
fn is_error() {
assert!(!ResponseType::Created.is_error());
assert!(!ResponseType::Continue.is_error());
assert!(ResponseType::BadRequest.is_error());
assert!(ResponseType::TooManyRequests.is_error());
assert!(ResponseType::HopLimitReached.is_error());
}
}

0 comments on commit 41e3bea

Please sign in to comment.