alloy_primitives/signed/
errors.rs1use core::fmt;
2use ruint::BaseConvertError;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub enum ParseSignedError {
7 Ruint(ruint::ParseError),
9
10 IntegerOverflow,
13}
14
15impl From<ruint::ParseError> for ParseSignedError {
16 fn from(err: ruint::ParseError) -> Self {
17 match err {
20 ruint::ParseError::BaseConvertError(BaseConvertError::Overflow) => {
21 Self::IntegerOverflow
22 }
23 _ => Self::Ruint(err),
24 }
25 }
26}
27
28#[cfg(feature = "std")]
29impl std::error::Error for ParseSignedError {
30 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
31 match self {
32 Self::Ruint(err) => Some(err),
33 Self::IntegerOverflow => None,
34 }
35 }
36}
37
38impl fmt::Display for ParseSignedError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Self::Ruint(e) => e.fmt(f),
42 Self::IntegerOverflow => f.write_str("number does not fit in the integer size"),
43 }
44 }
45}
46
47#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub struct BigIntConversionError;
50
51#[cfg(feature = "std")]
52impl std::error::Error for BigIntConversionError {}
53
54impl fmt::Display for BigIntConversionError {
55 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56 f.write_str("output of range integer conversion attempted")
57 }
58}