mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-02 15:24:57 +00:00
don't use allocated values in errors
This commit is contained in:
parent
c284ed562f
commit
2d67ab2b5e
@ -36,7 +36,7 @@ pub(crate) enum ErrorKind {
|
|||||||
Nil,
|
Nil,
|
||||||
/// A system time was invalid.
|
/// A system time was invalid.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
InvalidSystemTime(crate::std::string::String),
|
InvalidSystemTime(&'static str),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A string that is guaranteed to fail to parse to a [`Uuid`].
|
/// A string that is guaranteed to fail to parse to a [`Uuid`].
|
||||||
|
@ -196,9 +196,7 @@ impl std::convert::TryFrom<std::time::SystemTime> for Timestamp {
|
|||||||
/// This method will fail if the system time is earlier than the Unix Epoch.
|
/// This method will fail if the system time is earlier than the Unix Epoch.
|
||||||
/// On some platforms it may panic instead.
|
/// On some platforms it may panic instead.
|
||||||
fn try_from(st: std::time::SystemTime) -> Result<Self, Self::Error> {
|
fn try_from(st: std::time::SystemTime) -> Result<Self, Self::Error> {
|
||||||
use crate::std::string::ToString;
|
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")))?;
|
||||||
|
|
||||||
let dur = st.duration_since(std::time::UNIX_EPOCH).map_err(|e| crate::Error(crate::error::ErrorKind::InvalidSystemTime(e.to_string())))?;
|
|
||||||
|
|
||||||
Ok(Self::from_unix_time(
|
Ok(Self::from_unix_time(
|
||||||
dur.as_secs(),
|
dur.as_secs(),
|
||||||
@ -1260,10 +1258,7 @@ mod test_conversion {
|
|||||||
fn from_system_time_before_epoch() {
|
fn from_system_time_before_epoch() {
|
||||||
let before_epoch = match SystemTime::UNIX_EPOCH.checked_sub(Duration::from_nanos(1_000)) {
|
let before_epoch = match SystemTime::UNIX_EPOCH.checked_sub(Duration::from_nanos(1_000)) {
|
||||||
Some(st) => st,
|
Some(st) => st,
|
||||||
None => {
|
None => return,
|
||||||
println!("SystemTime before UNIX_EPOCH is not supported on this platform");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Timestamp::try_from(before_epoch)
|
Timestamp::try_from(before_epoch)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user