use derive_more::{Display, Error};
#[derive(Debug, Display, Error, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CounterError {
#[display("counter error: the time-stamp counter's rate follows the core's")]
NotInvariant,
#[display("counter error: the CPU reports no rate, and none could be measured")]
NoRate,
#[display("counter error: a rate of {hertz} Hz is outside 1 MHz to 10 GHz")]
ImplausibleRate {
hertz: u64,
},
}
#[cfg(test)]
mod tests {
use alloc::string::{String, ToString as _};
use rstest::rstest;
use crate::CounterError;
#[rstest]
#[case::not_invariant(
CounterError::NotInvariant.to_string(),
"counter error: the time-stamp counter's rate follows the core's"
)]
#[case::no_rate(
CounterError::NoRate.to_string(),
"counter error: the CPU reports no rate, and none could be measured"
)]
#[case::implausible_rate(
CounterError::ImplausibleRate { hertz: 42 }.to_string(),
"counter error: a rate of 42 Hz is outside 1 MHz to 10 GHz"
)]
fn each_refusal_says_why(#[case] message: String, #[case] text: &str) {
assert_eq!(message, text, "the message names what went wrong");
}
}