Skip to content

Commit 6ffb135

Browse files
committed
style: fix clippy issues
1 parent f15a31a commit 6ffb135

File tree

10 files changed

+39
-39
lines changed

10 files changed

+39
-39
lines changed

src/integrations/duration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ impl Interval {
1212
let mut days = duration.num_days();
1313
let mut new_dur = duration - Duration::days(days);
1414
let mut hours = duration.num_hours();
15-
new_dur = new_dur - Duration::hours(hours);
15+
new_dur -= Duration::hours(hours);
1616
let minutes = new_dur.num_minutes();
17-
new_dur = new_dur - Duration::minutes(minutes);
17+
new_dur -= Duration::minutes(minutes);
1818
let nano_secs = new_dur.num_nanoseconds()?;
19-
if days > (i32::max_value() as i64) {
20-
let overflow_days = days - (i32::max_value() as i64);
19+
if days > (i32::MAX as i64) {
20+
let overflow_days = days - (i32::MAX as i64);
2121
let added_hours = overflow_days.checked_mul(24)?;
2222
hours = hours.checked_add(added_hours)?;
2323
days -= overflow_days;

src/interval_fmt/iso_8601.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ impl IntervalNorm {
3636
if self.days != 0 {
3737
day_interval.push_str(&format!("{}D", self.days));
3838
}
39-
year_interval.push_str(&*day_interval);
40-
year_interval.push_str(&*time_interval);
39+
year_interval.push_str(&day_interval);
40+
year_interval.push_str(&time_interval);
4141
year_interval
4242
}
4343
}

src/interval_fmt/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ use std::ops::Neg;
77
/// Safely maps a i64 value to a unsigned number
88
/// without any overflow issues.
99
fn safe_abs_u64(mut num: i64) -> u64 {
10-
let max = i64::max_value();
10+
let max = i64::MAX;
1111
let max_min = max.neg();
1212
if num <= max_min {
1313
let result = max as u64;
1414
num += max;
1515
num *= -1;
1616
result + num as u64
1717
} else {
18-
num.abs() as u64
18+
num.unsigned_abs()
1919
}
2020
}
2121

2222
/// Safely maps a i32 value to a unsigned number
2323
/// without any overflow issues.
2424
fn safe_abs_u32(mut num: i32) -> u32 {
25-
let max = i32::max_value();
25+
let max = i32::MAX;
2626
let max_min = max.neg();
2727
if num <= max_min {
2828
let result = max as u32;
2929
num += max;
3030
num *= -1;
3131
result + num as u32
3232
} else {
33-
num.abs() as u32
33+
num.unsigned_abs()
3434
}
3535
}
3636

@@ -41,7 +41,7 @@ fn pad_i64(val: i64) -> String {
4141
} else {
4242
val as u64
4343
};
44-
return format!("{:02}", num);
44+
format!("{:02}", num)
4545
}
4646

4747
#[cfg(test)]
@@ -50,15 +50,15 @@ mod tests {
5050

5151
#[test]
5252
fn abs_safe_u32() {
53-
let min = i32::min_value();
53+
let min = i32::MIN;
5454
let actual = safe_abs_u32(min);
5555
let expected = 2147483648;
5656
assert_eq!(actual, expected);
5757
}
5858

5959
#[test]
6060
fn abs_safe_u64() {
61-
let min = i64::min_value();
61+
let min = i64::MIN;
6262
let actual = safe_abs_u64(min);
6363
let expected = 9_223_372_036_854_775_808;
6464
assert_eq!(actual, expected);

src/interval_fmt/postgres.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ impl IntervalNorm {
1414
}
1515
if self.is_year_month_present() {
1616
if self.years != 0 {
17-
year_interval.push_str(&*format!("{:#?} year ", self.years))
17+
year_interval.push_str(&format!("{:#?} year ", self.years))
1818
}
1919
if self.months != 0 {
20-
year_interval.push_str(&*format!("{:#?} mons ", self.months));
20+
year_interval.push_str(&format!("{:#?} mons ", self.months));
2121
}
2222
}
23-
year_interval.push_str(&*day_interval);
24-
year_interval.push_str(&*time_interval);
23+
year_interval.push_str(&day_interval);
24+
year_interval.push_str(&time_interval);
2525
year_interval.trim().to_owned()
2626
}
2727

@@ -35,15 +35,15 @@ impl IntervalNorm {
3535
};
3636
let hours = super::pad_i64(self.hours);
3737
time_interval.push_str(
38-
&*(sign
38+
&(sign
3939
+ &hours
4040
+ ":"
4141
+ &super::pad_i64(self.minutes)
4242
+ ":"
4343
+ &super::pad_i64(self.seconds)),
4444
);
4545
if self.microseconds != 0 {
46-
time_interval.push_str(&*format!(".{:06}", super::safe_abs_u64(self.microseconds)))
46+
time_interval.push_str(&format!(".{:06}", super::safe_abs_u64(self.microseconds)))
4747
}
4848
}
4949
time_interval

src/interval_norm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct IntervalNorm {
1010
pub microseconds: i64,
1111
}
1212

13-
impl<'a> From<&'a Interval> for IntervalNorm {
13+
impl From<&Interval> for IntervalNorm {
1414
fn from(val: &Interval) -> IntervalNorm {
1515
// grab the base values from the interval
1616
let months = val.months;

src/interval_parse/iso_8601.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Interval {
1717
let delim = vec!['Y', 'M', 'D', 'H', 'S'];
1818
let mut number = String::new();
1919
let mut interval_norm = IntervalNorm::default();
20-
if iso_str.rfind('P').map_or(false, |v| v == 1) {
20+
if iso_str.rfind('P') == Some(1) {
2121
Err(ParseError::from_invalid_interval(
2222
"Invalid format must start with P.",
2323
))
@@ -104,7 +104,7 @@ impl Interval {
104104
fn consume_number<'a>(val: &'a char, number: &'a mut String, delim: &[char]) -> ParserCode {
105105
let is_first_char = number.is_empty() && *val == '-';
106106
let is_period_char = !number.is_empty() && *val == '.';
107-
if val.is_digit(10) || is_first_char || is_period_char {
107+
if val.is_ascii_digit() || is_first_char || is_period_char {
108108
number.push(*val);
109109
ParserCode::Good
110110
} else if delim.contains(val) {
@@ -116,7 +116,7 @@ fn consume_number<'a>(val: &'a char, number: &'a mut String, delim: &[char]) ->
116116

117117
fn parse_number(number: &mut String) -> Result<f64, ParseError> {
118118
let parse_num = number.parse::<f64>()?;
119-
if parse_num > i32::max_value() as f64 {
119+
if parse_num > i32::MAX as f64 {
120120
Err(ParseError::from_invalid_interval("Exceeded max value"))
121121
} else {
122122
*number = "".to_owned();
@@ -257,19 +257,19 @@ mod tests {
257257
#[test]
258258
fn test_from_8601_19() {
259259
let interval = Interval::from_iso("PTT");
260-
assert_eq!(interval.is_err(), true);
260+
assert!(interval.is_err());
261261
}
262262

263263
#[test]
264264
fn test_from_8601_20() {
265265
let interval = Interval::from_iso("PT-");
266-
assert_eq!(interval.is_err(), true);
266+
assert!(interval.is_err());
267267
}
268268

269269
#[test]
270270
fn test_from_8601_21() {
271271
let interval = Interval::from_iso("PT10");
272-
assert_eq!(interval.is_err(), true);
272+
assert!(interval.is_err());
273273
}
274274

275275
#[test]

src/interval_parse/postgres.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ fn split_token(val: &str) -> Result<(String, String), ParseError> {
8888
}
8989

9090
/// Consume the token parts and add to the normalized interval.
91-
fn consume_token<'a>(
91+
fn consume_token(
9292
interval: &mut IntervalNorm,
9393
val: f64,
9494
delim: String,
95-
delim_list: &mut Vec<&'a str>,
95+
delim_list: &mut Vec<&str>,
9696
) -> Result<(), ParseError> {
9797
// Unlike iso8601 the delimiter can only appear once
9898
// so we need to check if the token can be found in
@@ -325,19 +325,19 @@ mod tests {
325325
#[test]
326326
fn test_from_postgres_24() {
327327
let interval = Interval::from_postgres("years 1");
328-
assert_eq!(interval.is_err(), true);
328+
assert!(interval.is_err());
329329
}
330330

331331
#[test]
332332
fn test_from_postgres_25() {
333333
let interval = Interval::from_postgres("- years");
334-
assert_eq!(interval.is_err(), true);
334+
assert!(interval.is_err());
335335
}
336336

337337
#[test]
338338
fn test_from_postgres_26() {
339339
let interval = Interval::from_postgres("10");
340-
assert_eq!(interval.is_err(), true);
340+
assert!(interval.is_err());
341341
}
342342

343343
#[test]
@@ -364,7 +364,7 @@ mod tests {
364364
#[test]
365365
fn test_from_postgres_30() {
366366
let interval = Interval::from_postgres("!");
367-
assert_eq!(interval.is_err(), true);
367+
assert!(interval.is_err());
368368
}
369369

370370
}

src/pg_interval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod tests {
5656
#[test]
5757
fn test_clone() {
5858
let interval = Interval::new(1, 1, 30);
59-
let test_interval = interval.clone();
59+
let test_interval = interval;
6060
assert_eq!(interval, test_interval);
6161
}
6262

src/pg_interval_add.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ mod tests {
9696
#[test]
9797
fn test_checked_add_2() {
9898
let interval = Interval::new(13, 0, 0);
99-
let interval_add = Interval::new(i32::max_value(), 1, 12);
99+
let interval_add = Interval::new(i32::MAX, 1, 12);
100100
let result = interval.checked_add(interval_add);
101101
assert_eq!(result, None);
102102
}
@@ -110,7 +110,7 @@ mod tests {
110110

111111
#[test]
112112
fn test_checked_add_day_time_2() {
113-
let interval = Interval::new(13, i32::max_value(), 0);
113+
let interval = Interval::new(13, i32::MAX, 0);
114114
let result = interval.checked_add_day_time(200, 0, 0, 2.123456789);
115115
assert_eq!(result, None);
116116
}
@@ -132,7 +132,7 @@ mod tests {
132132
#[test]
133133
fn checked_add_year_month_2() {
134134
let interval = Interval::new(15, 0, 0);
135-
let result = interval.checked_add_year_month(i32::max_value(), 32);
135+
let result = interval.checked_add_year_month(i32::MAX, 32);
136136
assert_eq!(result, None);
137137
}
138138

src/pg_interval_sub.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mod tests {
104104

105105
#[test]
106106
fn test_checked_sub_day_time_2() {
107-
let interval = Interval::new(13, i32::min_value(), 0);
107+
let interval = Interval::new(13, i32::MIN, 0);
108108
println!("{:?}", interval.days);
109109
let result = interval.checked_sub_day_time(100, 0, 0, 2.12);
110110
println!("{:?}", result);
@@ -128,7 +128,7 @@ mod tests {
128128
#[test]
129129
fn test_checked_sub_year_month_2() {
130130
let interval = Interval::new(-20, 0, 0);
131-
let result = interval.checked_sub_year_month(i32::min_value(), 1);
131+
let result = interval.checked_sub_year_month(i32::MIN, 1);
132132
assert_eq!(result, None);
133133
}
134134

@@ -151,7 +151,7 @@ mod tests {
151151
#[test]
152152
fn test_checked_sub_2() {
153153
let interval = Interval::new(-10, 0, 0);
154-
let interval_sub = Interval::new(i32::max_value(), 0, 0);
154+
let interval_sub = Interval::new(i32::MAX, 0, 0);
155155
let result = interval.checked_sub(interval_sub);
156156
assert_eq!(result, None);
157157
}

0 commit comments

Comments
 (0)