1use rand_core::{Error, ErrorKind};
11use core::fmt;
12
13#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum TimerError {
18 NoTimer,
20 CoarseTimer,
22 NotMonotonic,
24 TinyVariantions,
26 TooManyStuck,
28 #[doc(hidden)]
29 __Nonexhaustive,
30}
31
32impl TimerError {
33 fn description(&self) -> &'static str {
34 match *self {
35 TimerError::NoTimer => "no timer available",
36 TimerError::CoarseTimer => "coarse timer",
37 TimerError::NotMonotonic => "timer not monotonic",
38 TimerError::TinyVariantions => "time delta variations too small",
39 TimerError::TooManyStuck => "too many stuck results",
40 TimerError::__Nonexhaustive => unreachable!(),
41 }
42 }
43}
44
45impl fmt::Display for TimerError {
46 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47 write!(f, "{}", self.description())
48 }
49}
50
51#[cfg(feature = "std")]
52impl ::std::error::Error for TimerError {
53 fn description(&self) -> &str {
54 self.description()
55 }
56}
57
58impl From<TimerError> for Error {
59 fn from(err: TimerError) -> Error {
60 #[cfg(feature = "std")] {
63 Error::with_cause(ErrorKind::Unavailable, "timer jitter failed basic quality tests", err)
64 }
65 #[cfg(not(feature = "std"))] {
66 Error::new(ErrorKind::Unavailable, "timer jitter failed basic quality tests")
67 }
68 }
69}
70