@@ 28,7 28,7 @@ where
let m2 = next_digit(chars)?;
let month = m1 * 10 + m2;
- if month < 1 || month > 12 {
+ if !(1..=12).contains(&month) {
return Err(Rfc3339Error::MonthOutOfRange(month));
}
@@ 38,7 38,7 @@ where
let d2 = next_digit(chars)?;
let day = d1 * 10 + d2;
- if day < 1 || day > 31 {
+ if !(1..=31).contains(&day) {
return Err(Rfc3339Error::DayOutOfRange(day));
}
@@ 78,9 78,8 @@ where
while let Some(c) = chars.next() {
match c {
'.' => {
- let mut chars_tmp = chars.clone();
let mut p = 0;
- while let Some(c) = chars_tmp.next() {
+ for c in chars.clone() {
match c {
'0'..='9' => {
if p < 9 {
@@ 109,7 108,7 @@ where
offset_minutes = sign * (hour * 60 + minute);
- if offset_minutes > 24 * 60 || offset_minutes < -24 * 60 {
+ if !(-24 * 60..=24 * 60).contains(&offset_minutes) {
return Err(Rfc3339Error::OffsetOutOfRange(offset_minutes));
}
}
@@ 195,12 194,12 @@ impl Display for Rfc3339Error {
ExpectedColon => write!(f, "expected colon"),
ExpectedTimeSep => write!(f, "expected time separator"),
ExpectedTab => write!(f, "expected tab"),
- MonthOutOfRange(m) => write!(f, "month out of range: {}", m),
- DayOutOfRange(d) => write!(f, "day out of range: {}", d),
- HourOutOfRange(h) => write!(f, "hour out of range: {}", h),
- MinuteOutOfRange(m) => write!(f, "minute out of range: {}", m),
- SecondOutOfRange(s) => write!(f, "second out of range: {}", s),
- OffsetOutOfRange(o) => write!(f, "offset out of range: {}", o),
+ MonthOutOfRange(m) => write!(f, "month out of range: {m}"),
+ DayOutOfRange(d) => write!(f, "day out of range: {d}"),
+ HourOutOfRange(h) => write!(f, "hour out of range: {h}"),
+ MinuteOutOfRange(m) => write!(f, "minute out of range: {m}"),
+ SecondOutOfRange(s) => write!(f, "second out of range: {s}"),
+ OffsetOutOfRange(o) => write!(f, "offset out of range: {o}"),
}
}
}
@@ 9,5 9,5 @@ const TEST: &str = "
fn main() {
let twt = parse_twts(TEST.as_bytes()).unwrap();
- println!("{:?}", twt);
+ println!("{twt:?}");
}