Skip to content

Commit b74ebe8

Browse files
committed
Use new feature of deranged
1 parent d671910 commit b74ebe8

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ time-core = { path = "time-core", version = "=0.1.1" }
88
time-macros = { path = "time-macros", version = "=0.2.11" }
99

1010
criterion = { version = "0.5.1", default-features = false }
11-
deranged = { version = "0.3.5", default-features = false }
11+
deranged = { version = "0.3.7", default-features = false }
1212
itoa = "1.0.1"
1313
js-sys = "0.3.58"
1414
libc = "0.2.98"

time/src/duration.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ pub(crate) enum Padding {
2626
type Nanoseconds =
2727
RangedI32<{ -(Nanosecond.per(Second) as i32 - 1) }, { Nanosecond.per(Second) as i32 - 1 }>;
2828

29-
/// A value for the `nanoseconds` field that is exactly zero.
30-
///
31-
/// This is used in a few locations, so centralizing the `unsafe` makes sense.
32-
// Safety: Zero is in range.
33-
#[allow(clippy::undocumented_unsafe_blocks)] // rust-lang/rust-clippy#11246
34-
const ZERO: Nanoseconds = unsafe { Nanoseconds::new_unchecked(0) };
35-
3629
/// A span of time with nanosecond precision.
3730
///
3831
/// Each `Duration` is composed of a whole number of seconds and a fractional part represented in
@@ -63,7 +56,7 @@ impl Default for Duration {
6356
fn default() -> Self {
6457
Self {
6558
seconds: 0,
66-
nanoseconds: ZERO,
59+
nanoseconds: Nanoseconds::new_static::<0>(),
6760
padding: Padding::Optimize,
6861
}
6962
}
@@ -164,7 +157,7 @@ macro_rules! try_from_secs {
164157
// following numbers -128..=127. The check above (exp < 63)
165158
// doesn't cover i64::MIN as that is -2^63, so we have this
166159
// additional case to handle the asymmetry of iN::MIN.
167-
break 'value Self::new_ranged_unchecked(i64::MIN, ZERO);
160+
break 'value Self::new_ranged_unchecked(i64::MIN, Nanoseconds::new_static::<0>());
168161
} else if $secs.is_nan() {
169162
// Change from std: std doesn't differentiate between the error
170163
// cases.
@@ -491,7 +484,7 @@ impl Duration {
491484
/// assert_eq!(Duration::seconds(1), 1_000.milliseconds());
492485
/// ```
493486
pub const fn seconds(seconds: i64) -> Self {
494-
Self::new_ranged_unchecked(seconds, ZERO)
487+
Self::new_ranged_unchecked(seconds, Nanoseconds::new_static::<0>())
495488
}
496489

497490
/// Creates a new `Duration` from the specified number of seconds represented as `f64`.

0 commit comments

Comments
 (0)