Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use range.contains in StatusCode methods #748

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::str::FromStr;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StatusCode(NonZeroU16);

/// A possible error value when converting a `StatusCode` from a `u16` or `&str`
/// A possible error value when converting a `StatusCode` from a `u16` or `&str`.
///
/// This error indicates that the supplied input was not a valid number, was less
/// than 100, or was greater than 999.
Expand Down Expand Up @@ -80,7 +80,7 @@ impl StatusCode {
.ok_or_else(InvalidStatusCode::new)
}

/// Converts a &[u8] to a status code
/// Converts a `&[u8]` to a status code.
pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode> {
if src.len() != 3 {
return Err(InvalidStatusCode::new());
Expand Down Expand Up @@ -117,7 +117,7 @@ impl StatusCode {
/// ```
#[inline]
pub const fn as_u16(&self) -> u16 {
(*self).0.get()
self.0.get()
}

/// Returns a &str representation of the `StatusCode`
Expand Down Expand Up @@ -175,31 +175,31 @@ impl StatusCode {
/// Check if status is within 100-199.
#[inline]
pub fn is_informational(&self) -> bool {
200 > self.0.get() && self.0.get() >= 100
(100..200).contains(&self.0.get())
}

/// Check if status is within 200-299.
#[inline]
pub fn is_success(&self) -> bool {
300 > self.0.get() && self.0.get() >= 200
(200..300).contains(&self.0.get())
}

/// Check if status is within 300-399.
#[inline]
pub fn is_redirection(&self) -> bool {
400 > self.0.get() && self.0.get() >= 300
(300..400).contains(&self.0.get())
}

/// Check if status is within 400-499.
#[inline]
pub fn is_client_error(&self) -> bool {
500 > self.0.get() && self.0.get() >= 400
(400..500).contains(&self.0.get())
}

/// Check if status is within 500-599.
#[inline]
pub fn is_server_error(&self) -> bool {
600 > self.0.get() && self.0.get() >= 500
(500..600).contains(&self.0.get())
}
}

Expand Down