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
28impl core::error::Error for ParseSignedError {
29 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
30 match self {
31 #[cfg(feature = "std")]
32 Self::Ruint(err) => Some(err),
33 _ => 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
51impl core::error::Error for BigIntConversionError {}
52
53impl fmt::Display for BigIntConversionError {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 f.write_str("output of range integer conversion attempted")
56 }
57}