From f1c72a538241174a161a2fca8948e852d4f55e5a Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 16 Mar 2024 07:10:14 +0100 Subject: [PATCH] Convert `TryFrom> for SystemTime` --- src/datetime/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 5ec7f765d4..84995d6ac0 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -26,7 +26,7 @@ use crate::naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime}; #[cfg(feature = "clock")] use crate::offset::Local; use crate::offset::{FixedOffset, MappedLocalTime, Offset, TimeZone, Utc}; -#[cfg(any(feature = "clock", feature = "std"))] +#[cfg(feature = "clock")] use crate::OutOfRange; use crate::{try_err, try_ok_or, Datelike, Error, Months, TimeDelta, Timelike, Weekday}; @@ -1759,16 +1759,16 @@ impl TryFrom for DateTime { #[cfg(feature = "std")] impl TryFrom> for SystemTime { - type Error = OutOfRange; + type Error = Error; - fn try_from(dt: DateTime) -> Result { + fn try_from(dt: DateTime) -> Result { let sec = dt.timestamp(); let sec_abs = sec.unsigned_abs(); let nsec = dt.timestamp_subsec_nanos(); if sec < 0 { // `dt` is before the Unix epoch. let mut t = - UNIX_EPOCH.checked_sub(Duration::new(sec_abs, 0)).ok_or_else(OutOfRange::new)?; + UNIX_EPOCH.checked_sub(Duration::new(sec_abs, 0)).ok_or(Error::OutOfRange)?; // Overflow safety: `t` is before the Unix epoch. Adding nanoseconds therefore cannot // overflow. @@ -1777,7 +1777,7 @@ impl TryFrom> for SystemTime { Ok(t) } else { // `dt` is after the Unix epoch. - UNIX_EPOCH.checked_add(Duration::new(sec_abs, nsec)).ok_or_else(OutOfRange::new) + UNIX_EPOCH.checked_add(Duration::new(sec_abs, nsec)).ok_or(Error::OutOfRange) } } }