Skip to content

Commit

Permalink
Apply Clippy suggestions for duration module
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Jun 1, 2023
1 parent 05e2621 commit 853a575
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/duration.rs
Expand Up @@ -22,21 +22,21 @@ use rkyv::{Archive, Deserialize, Serialize};
/// The number of nanoseconds in a microsecond.
const NANOS_PER_MICRO: i32 = 1000;
/// The number of nanoseconds in a millisecond.
const NANOS_PER_MILLI: i32 = 1000_000;
const NANOS_PER_MILLI: i32 = 1_000_000;
/// The number of nanoseconds in seconds.
const NANOS_PER_SEC: i32 = 1_000_000_000;
/// The number of microseconds per second.
const MICROS_PER_SEC: i64 = 1000_000;
const MICROS_PER_SEC: i64 = 1_000_000;
/// The number of milliseconds per second.
const MILLIS_PER_SEC: i64 = 1000;
/// The number of seconds in a minute.
const SECS_PER_MINUTE: i64 = 60;
/// The number of seconds in an hour.
const SECS_PER_HOUR: i64 = 3600;
/// The number of (non-leap) seconds in days.
const SECS_PER_DAY: i64 = 86400;
const SECS_PER_DAY: i64 = 86_400;
/// The number of (non-leap) seconds in a week.
const SECS_PER_WEEK: i64 = 604800;
const SECS_PER_WEEK: i64 = 604_800;

macro_rules! try_opt {
($e:expr) => {
Expand Down Expand Up @@ -128,22 +128,22 @@ impl Duration {
pub const fn milliseconds(milliseconds: i64) -> Duration {
let (secs, millis) = div_mod_floor_64(milliseconds, MILLIS_PER_SEC);
let nanos = millis as i32 * NANOS_PER_MILLI;
Duration { secs: secs, nanos: nanos }
Duration { secs, nanos }
}

/// Makes a new `Duration` with given number of microseconds.
#[inline]
pub const fn microseconds(microseconds: i64) -> Duration {
let (secs, micros) = div_mod_floor_64(microseconds, MICROS_PER_SEC);
let nanos = micros as i32 * NANOS_PER_MICRO;
Duration { secs: secs, nanos: nanos }
Duration { secs, nanos }
}

/// Makes a new `Duration` with given number of nanoseconds.
#[inline]
pub const fn nanoseconds(nanos: i64) -> Duration {
let (secs, nanos) = div_mod_floor_64(nanos, NANOS_PER_SEC as i64);
Duration { secs: secs, nanos: nanos as i32 }
Duration { secs, nanos: nanos as i32 }
}

/// Returns the total number of whole weeks in the duration.
Expand Down Expand Up @@ -224,7 +224,7 @@ impl Duration {
nanos -= NANOS_PER_SEC;
secs = try_opt!(secs.checked_add(1));
}
let d = Duration { secs: secs, nanos: nanos };
let d = Duration { secs, nanos };
// Even if d is within the bounds of i64 seconds,
// it might still overflow i64 milliseconds.
if d < MIN || d > MAX {
Expand All @@ -243,7 +243,7 @@ impl Duration {
nanos += NANOS_PER_SEC;
secs = try_opt!(secs.checked_sub(1));
}
let d = Duration { secs: secs, nanos: nanos };
let d = Duration { secs, nanos };
// Even if d is within the bounds of i64 seconds,
// it might still overflow i64 milliseconds.
if d < MIN || d > MAX {
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Add for Duration {
nanos -= NANOS_PER_SEC;
secs += 1;
}
Duration { secs: secs, nanos: nanos }
Duration { secs, nanos }
}
}

Expand All @@ -352,7 +352,7 @@ impl Sub for Duration {
nanos += NANOS_PER_SEC;
secs -= 1;
}
Duration { secs: secs, nanos: nanos }
Duration { secs, nanos }
}
}

Expand All @@ -364,7 +364,7 @@ impl Mul<i32> for Duration {
let total_nanos = self.nanos as i64 * rhs as i64;
let (extra_secs, nanos) = div_mod_floor_64(total_nanos, NANOS_PER_SEC as i64);
let secs = self.secs * rhs as i64 + extra_secs;
Duration { secs: secs, nanos: nanos as i32 }
Duration { secs, nanos: nanos as i32 }
}
}

Expand All @@ -384,7 +384,7 @@ impl Div<i32> for Duration {
nanos += NANOS_PER_SEC;
secs -= 1;
}
Duration { secs: secs, nanos: nanos }
Duration { secs, nanos }
}
}

Expand Down

0 comments on commit 853a575

Please sign in to comment.