use crate::time::Duration;
pub trait SystemTime {
fn duration_since_epoch() -> Result<Duration, SystemTimeError>;
}
pub trait SystemTimeSync {
fn set_system_time(elapsed_from_epoch: Duration) -> Result<(), SystemTimeError>;
}
#[derive(Debug, Eq, PartialEq)]
pub enum SystemTimeError {
Unsynchronized,
EpochIsLaterThanStartTime,
}
impl core::error::Error for SystemTimeError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
match self {
SystemTimeError::Unsynchronized => None,
SystemTimeError::EpochIsLaterThanStartTime => None,
}
}
}
impl core::fmt::Display for SystemTimeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
SystemTimeError::Unsynchronized => write!(f, "{self:?}"),
SystemTimeError::EpochIsLaterThanStartTime => write!(f, "{self:?}"),
}
}
}