Skip to content

Commit 2d67ab2

Browse files
committed
don't use allocated values in errors
1 parent c284ed5 commit 2d67ab2

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) enum ErrorKind {
3636
Nil,
3737
/// A system time was invalid.
3838
#[cfg(feature = "std")]
39-
InvalidSystemTime(crate::std::string::String),
39+
InvalidSystemTime(&'static str),
4040
}
4141

4242
/// A string that is guaranteed to fail to parse to a [`Uuid`].

src/timestamp.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ impl std::convert::TryFrom<std::time::SystemTime> for Timestamp {
196196
/// This method will fail if the system time is earlier than the Unix Epoch.
197197
/// On some platforms it may panic instead.
198198
fn try_from(st: std::time::SystemTime) -> Result<Self, Self::Error> {
199-
use crate::std::string::ToString;
200-
201-
let dur = st.duration_since(std::time::UNIX_EPOCH).map_err(|e| crate::Error(crate::error::ErrorKind::InvalidSystemTime(e.to_string())))?;
199+
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")))?;
202200

203201
Ok(Self::from_unix_time(
204202
dur.as_secs(),
@@ -1260,10 +1258,7 @@ mod test_conversion {
12601258
fn from_system_time_before_epoch() {
12611259
let before_epoch = match SystemTime::UNIX_EPOCH.checked_sub(Duration::from_nanos(1_000)) {
12621260
Some(st) => st,
1263-
None => {
1264-
println!("SystemTime before UNIX_EPOCH is not supported on this platform");
1265-
return;
1266-
}
1261+
None => return,
12671262
};
12681263

12691264
Timestamp::try_from(before_epoch)

0 commit comments

Comments
 (0)