Skip to content

Commit b03ed6a

Browse files
authored
chore: use range.contains in StatusCode methods (#748)
Small change for readability, alongside some minor documentation touchups for consistency.
1 parent a463fb5 commit b03ed6a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/status.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::str::FromStr;
4444
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4545
pub struct StatusCode(NonZeroU16);
4646

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

83-
/// Converts a &[u8] to a status code
83+
/// Converts a `&[u8]` to a status code.
8484
pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode> {
8585
if src.len() != 3 {
8686
return Err(InvalidStatusCode::new());
@@ -117,7 +117,7 @@ impl StatusCode {
117117
/// ```
118118
#[inline]
119119
pub const fn as_u16(&self) -> u16 {
120-
(*self).0.get()
120+
self.0.get()
121121
}
122122

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

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

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

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

199199
/// Check if status is within 500-599.
200200
#[inline]
201201
pub fn is_server_error(&self) -> bool {
202-
600 > self.0.get() && self.0.get() >= 500
202+
(500..600).contains(&self.0.get())
203203
}
204204
}
205205

0 commit comments

Comments
 (0)