clockctrl/
error.rs

1use std::error::Error as StdError;
2use std::fmt::{self, Display, Formatter};
3
4/// An Error type for various clock related failures
5///
6/// These are returned when creating and validating clock inputs.
7/// Because internal tasks are running detached with no way to return
8/// Errors to the library user, the core will simply crash if the
9/// results are ignored.
10#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
11pub enum Error {
12    /// Either the Interval or offset was invalid
13    InvalidTime,
14    /// Set the clock type to `Stepped` but didn't provide a fence
15    NoFence,
16    /// No interval was provided
17    NoInterval,
18    /// The requested target has no settings attached to it
19    NoTarget,
20}
21
22impl Display for Error {
23    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
24        write!(
25            f,
26            "{}",
27            match self {
28                Error::InvalidTime => "Provided time was invalid (probably 0)",
29                Error::NoFence => "Stepped is impossible without providing a fence",
30                Error::NoInterval => "No interval known for a clock value",
31                Error::NoTarget => "The requested target has no settings attached",
32            }
33        )
34    }
35}
36
37impl StdError for Error {}