From 2d67ab2b5e261a68fb65a5bee50604516537307b Mon Sep 17 00:00:00 2001 From: KodrAus Date: Sat, 9 Aug 2025 20:08:41 +1000 Subject: [PATCH] don't use allocated values in errors --- src/error.rs | 2 +- src/timestamp.rs | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/error.rs b/src/error.rs index ef60349..4371c02 100644 --- a/src/error.rs +++ b/src/error.rs @@ -36,7 +36,7 @@ pub(crate) enum ErrorKind { Nil, /// A system time was invalid. #[cfg(feature = "std")] - InvalidSystemTime(crate::std::string::String), + InvalidSystemTime(&'static str), } /// A string that is guaranteed to fail to parse to a [`Uuid`]. diff --git a/src/timestamp.rs b/src/timestamp.rs index 45bcfa1..eb68309 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -196,9 +196,7 @@ impl std::convert::TryFrom for Timestamp { /// This method will fail if the system time is earlier than the Unix Epoch. /// On some platforms it may panic instead. fn try_from(st: std::time::SystemTime) -> Result { - use crate::std::string::ToString; - - let dur = st.duration_since(std::time::UNIX_EPOCH).map_err(|e| crate::Error(crate::error::ErrorKind::InvalidSystemTime(e.to_string())))?; + let dur = st.duration_since(std::time::UNIX_EPOCH).map_err(|_| crate::Error(crate::error::ErrorKind::InvalidSystemTime("unable to convert the system tie into a Unix timestamp")))?; Ok(Self::from_unix_time( dur.as_secs(), @@ -1260,10 +1258,7 @@ mod test_conversion { fn from_system_time_before_epoch() { let before_epoch = match SystemTime::UNIX_EPOCH.checked_sub(Duration::from_nanos(1_000)) { Some(st) => st, - None => { - println!("SystemTime before UNIX_EPOCH is not supported on this platform"); - return; - } + None => return, }; Timestamp::try_from(before_epoch)