alloy_primitives/signed/
errors.rsuse core::fmt;
use ruint::BaseConvertError;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ParseSignedError {
Ruint(ruint::ParseError),
IntegerOverflow,
}
impl From<ruint::ParseError> for ParseSignedError {
fn from(err: ruint::ParseError) -> Self {
match err {
ruint::ParseError::BaseConvertError(BaseConvertError::Overflow) => {
Self::IntegerOverflow
}
_ => Self::Ruint(err),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for ParseSignedError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Ruint(err) => Some(err),
Self::IntegerOverflow => None,
}
}
}
impl fmt::Display for ParseSignedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Ruint(e) => e.fmt(f),
Self::IntegerOverflow => f.write_str("number does not fit in the integer size"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct BigIntConversionError;
#[cfg(feature = "std")]
impl std::error::Error for BigIntConversionError {}
impl fmt::Display for BigIntConversionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("output of range integer conversion attempted")
}
}