use core::fmt;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
IndexOutOfBounds {
index: usize,
min: usize,
max: usize,
},
InvalidFieldValue {
field: &'static str,
value: usize,
bitmask: usize,
},
InvalidFieldVariant { field: &'static str, value: usize },
InvalidValue { value: usize, bitmask: usize },
InvalidVariant(usize),
Unimplemented,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::IndexOutOfBounds { index, min, max } => write!(
f,
"out-of-bounds access, index: {index}, min: {min}, max: {max}"
),
Self::InvalidFieldValue {
field,
value,
bitmask,
} => write!(
f,
"invalid {field} field value: {value:#x}, valid bitmask: {bitmask:#x}",
),
Self::InvalidFieldVariant { field, value } => {
write!(f, "invalid {field} field variant: {value:#x}")
}
Self::InvalidValue { value, bitmask } => {
write!(f, "invalid value: {value:#x}, valid bitmask: {bitmask:#x}",)
}
Self::InvalidVariant(value) => {
write!(f, "invalid variant: {value:#x}")
}
Self::Unimplemented => write!(f, "unimplemented"),
}
}
}