#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct OverflowError<T = usize> {
pub max: T,
pub value: T,
}
impl core::fmt::Display for OverflowError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"Unable to construct bit-sized integer from a value `{}` overflowing max value `{}`",
self.value, self.max
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for OverflowError {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DivError {
ZeroDiv,
Overflow,
}
impl core::fmt::Display for DivError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
DivError::ZeroDiv => write!(f, "division by zero"),
DivError::Overflow => write!(f, "division with overflow"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for DivError {}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PositDecodeError {
Zero,
NaR,
}
impl core::fmt::Display for PositDecodeError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match *self {
PositDecodeError::Zero => write!(f, "exception value zero"),
PositDecodeError::NaR => write!(f, "exception value NaR"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for PositDecodeError {}
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct ParseLengthError {
pub actual: usize,
pub expected: usize,
}
impl core::fmt::Display for ParseLengthError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "Invalid length: got {}, expected {}", self.actual, self.expected)
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseLengthError {}