use rand_core::{Error, ErrorKind};
use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TimerError {
NoTimer,
CoarseTimer,
NotMonotonic,
TinyVariantions,
TooManyStuck,
#[doc(hidden)]
__Nonexhaustive,
}
impl TimerError {
fn description(&self) -> &'static str {
match *self {
TimerError::NoTimer => "no timer available",
TimerError::CoarseTimer => "coarse timer",
TimerError::NotMonotonic => "timer not monotonic",
TimerError::TinyVariantions => "time delta variations too small",
TimerError::TooManyStuck => "too many stuck results",
TimerError::__Nonexhaustive => unreachable!(),
}
}
}
impl fmt::Display for TimerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
#[cfg(feature = "std")]
impl ::std::error::Error for TimerError {
fn description(&self) -> &str {
self.description()
}
}
impl From<TimerError> for Error {
fn from(err: TimerError) -> Error {
#[cfg(feature = "std")] {
Error::with_cause(ErrorKind::Unavailable, "timer jitter failed basic quality tests", err)
}
#[cfg(not(feature = "std"))] {
Error::new(ErrorKind::Unavailable, "timer jitter failed basic quality tests")
}
}
}