use core::fmt;
#[cfg(not(feature = "std"))]
use core::error;
#[cfg(feature = "std")]
use std::error;
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct IntRegisterConversionError {
index: u32,
count: u32,
register_kind: &'static str,
}
impl IntRegisterConversionError {
pub(crate) const fn new_out_of_range(
index: u32,
count: u32,
register_kind: &'static str,
) -> Self {
Self {
index,
count,
register_kind,
}
}
}
impl fmt::Display for IntRegisterConversionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Index '{}' is out of range for register kind '{}', max value is {}.",
self.index, self.register_kind, self.count
)
}
}
impl error::Error for IntRegisterConversionError {}