#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
pub struct Time(u64);
impl Time {
#[cfg(feature = "std")]
pub fn try_from(time: std::time::SystemTime) -> Result<Self, ring::error::Unspecified> {
core::convert::TryFrom::try_from(time)
}
#[allow(clippy::must_use_candidate)]
pub fn from_seconds_since_unix_epoch(secs: u64) -> Self {
Self(secs)
}
}
#[cfg(feature = "std")]
impl core::convert::TryFrom<std::time::SystemTime> for Time {
type Error = ring::error::Unspecified;
fn try_from(value: std::time::SystemTime) -> Result<Self, Self::Error> {
value
.duration_since(std::time::UNIX_EPOCH)
.map(|d| Self::from_seconds_since_unix_epoch(d.as_secs()))
.map_err(|_| ring::error::Unspecified)
}
}