1use derive_more::{Display, Error};
4
5#[derive(Debug, Display, Error, Clone, Copy, PartialEq, Eq, Hash)]
19#[non_exhaustive]
20pub enum CounterError {
21 #[display("counter error: the time-stamp counter's rate follows the core's")]
23 NotInvariant,
24 #[display("counter error: the CPU reports no rate, and none could be measured")]
26 NoRate,
27 #[display("counter error: a rate of {hertz} Hz is outside 1 MHz to 10 GHz")]
29 ImplausibleRate {
30 hertz: u64,
32 },
33}
34
35#[cfg(test)]
36mod tests {
37 use alloc::string::{String, ToString as _};
38
39 use rstest::rstest;
40
41 use crate::CounterError;
42
43 #[rstest]
44 #[case::not_invariant(
45 CounterError::NotInvariant.to_string(),
46 "counter error: the time-stamp counter's rate follows the core's"
47 )]
48 #[case::no_rate(
49 CounterError::NoRate.to_string(),
50 "counter error: the CPU reports no rate, and none could be measured"
51 )]
52 #[case::implausible_rate(
53 CounterError::ImplausibleRate { hertz: 42 }.to_string(),
54 "counter error: a rate of 42 Hz is outside 1 MHz to 10 GHz"
55 )]
56 fn each_refusal_says_why(#[case] message: String, #[case] text: &str) {
57 assert_eq!(message, text, "the message names what went wrong");
58 }
59}