@@ -11,56 +11,56 @@ use super::INPUT_STRING_LEN_LIMIT;
1111
1212/// An error during amount parsing amount with denomination.
1313#[ derive( Debug , Clone , PartialEq , Eq ) ]
14- #[ non_exhaustive]
15- pub enum ParseError {
14+ pub struct ParseError ( pub ( crate ) ParseErrorInner ) ;
15+
16+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
17+ pub ( crate ) enum ParseErrorInner {
1618 /// Invalid amount.
1719 Amount ( ParseAmountError ) ,
18-
1920 /// Invalid denomination.
2021 Denomination ( ParseDenominationError ) ,
21-
2222 /// The denomination was not identified.
2323 MissingDenomination ( MissingDenominationError ) ,
2424}
2525
2626internals:: impl_from_infallible!( ParseError ) ;
27+ internals:: impl_from_infallible!( ParseErrorInner ) ;
2728
2829impl From < ParseAmountError > for ParseError {
29- fn from ( e : ParseAmountError ) -> Self { Self :: Amount ( e) }
30+ fn from ( e : ParseAmountError ) -> Self { Self ( ParseErrorInner :: Amount ( e) ) }
3031}
3132
3233impl From < ParseDenominationError > for ParseError {
33- fn from ( e : ParseDenominationError ) -> Self { Self :: Denomination ( e) }
34+ fn from ( e : ParseDenominationError ) -> Self { Self ( ParseErrorInner :: Denomination ( e) ) }
3435}
3536
3637impl From < OutOfRangeError > for ParseError {
37- fn from ( e : OutOfRangeError ) -> Self { Self :: Amount ( e. into ( ) ) }
38+ fn from ( e : OutOfRangeError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
3839}
3940
4041impl From < TooPreciseError > for ParseError {
41- fn from ( e : TooPreciseError ) -> Self { Self :: Amount ( e. into ( ) ) }
42+ fn from ( e : TooPreciseError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
4243}
4344
4445impl From < MissingDigitsError > for ParseError {
45- fn from ( e : MissingDigitsError ) -> Self { Self :: Amount ( e. into ( ) ) }
46+ fn from ( e : MissingDigitsError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
4647}
4748
4849impl From < InputTooLargeError > for ParseError {
49- fn from ( e : InputTooLargeError ) -> Self { Self :: Amount ( e. into ( ) ) }
50+ fn from ( e : InputTooLargeError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
5051}
5152
5253impl From < InvalidCharacterError > for ParseError {
53- fn from ( e : InvalidCharacterError ) -> Self { Self :: Amount ( e. into ( ) ) }
54+ fn from ( e : InvalidCharacterError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
5455}
5556
5657impl fmt:: Display for ParseError {
5758 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
58- match self {
59- ParseError :: Amount ( error) => write_err ! ( f, "invalid amount" ; error) ,
60- ParseError :: Denomination ( error) => write_err ! ( f, "invalid denomination" ; error) ,
61- // We consider this to not be a source because it currently doesn't contain useful
62- // information
63- ParseError :: MissingDenomination ( _) =>
59+ match self . 0 {
60+ ParseErrorInner :: Amount ( ref e) => write_err ! ( f, "invalid amount" ; e) ,
61+ ParseErrorInner :: Denomination ( ref e) => write_err ! ( f, "invalid denomination" ; e) ,
62+ // We consider this to not be a source because it currently doesn't contain useful info.
63+ ParseErrorInner :: MissingDenomination ( _) =>
6464 f. write_str ( "the input doesn't contain a denomination" ) ,
6565 }
6666 }
@@ -69,20 +69,21 @@ impl fmt::Display for ParseError {
6969#[ cfg( feature = "std" ) ]
7070impl std:: error:: Error for ParseError {
7171 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
72- match self {
73- ParseError :: Amount ( error) => Some ( error) ,
74- ParseError :: Denomination ( error) => Some ( error) ,
75- // We consider this to not be a source because it currently doesn't contain useful
76- // information
77- ParseError :: MissingDenomination ( _) => None ,
72+ match self . 0 {
73+ ParseErrorInner :: Amount ( ref e) => Some ( e) ,
74+ ParseErrorInner :: Denomination ( ref e) => Some ( e) ,
75+ // We consider this to not be a source because it currently doesn't contain useful info.
76+ ParseErrorInner :: MissingDenomination ( _) => None ,
7877 }
7978 }
8079}
8180
8281/// An error during amount parsing.
8382#[ derive( Debug , Clone , PartialEq , Eq ) ]
84- #[ non_exhaustive]
85- pub enum ParseAmountError {
83+ pub struct ParseAmountError ( pub ( crate ) ParseAmountErrorInner ) ;
84+
85+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
86+ pub ( crate ) enum ParseAmountErrorInner {
8687 /// The amount is too big or too small.
8788 OutOfRange ( OutOfRangeError ) ,
8889 /// Amount has higher precision than supported by the type.
@@ -96,28 +97,31 @@ pub enum ParseAmountError {
9697}
9798
9899impl From < TooPreciseError > for ParseAmountError {
99- fn from ( value : TooPreciseError ) -> Self { Self :: TooPrecise ( value) }
100+ fn from ( value : TooPreciseError ) -> Self { Self ( ParseAmountErrorInner :: TooPrecise ( value) ) }
100101}
101102
102103impl From < MissingDigitsError > for ParseAmountError {
103- fn from ( value : MissingDigitsError ) -> Self { Self :: MissingDigits ( value) }
104+ fn from ( value : MissingDigitsError ) -> Self { Self ( ParseAmountErrorInner :: MissingDigits ( value) ) }
104105}
105106
106107impl From < InputTooLargeError > for ParseAmountError {
107- fn from ( value : InputTooLargeError ) -> Self { Self :: InputTooLarge ( value) }
108+ fn from ( value : InputTooLargeError ) -> Self { Self ( ParseAmountErrorInner :: InputTooLarge ( value) ) }
108109}
109110
110111impl From < InvalidCharacterError > for ParseAmountError {
111- fn from ( value : InvalidCharacterError ) -> Self { Self :: InvalidCharacter ( value) }
112+ fn from ( value : InvalidCharacterError ) -> Self {
113+ Self ( ParseAmountErrorInner :: InvalidCharacter ( value) )
114+ }
112115}
113116
114117internals:: impl_from_infallible!( ParseAmountError ) ;
118+ internals:: impl_from_infallible!( ParseAmountErrorInner ) ;
115119
116120impl fmt:: Display for ParseAmountError {
117121 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
118- use ParseAmountError :: * ;
122+ use ParseAmountErrorInner :: * ;
119123
120- match * self {
124+ match self . 0 {
121125 OutOfRange ( ref error) => write_err ! ( f, "amount out of range" ; error) ,
122126 TooPrecise ( ref error) => write_err ! ( f, "amount has a too high precision" ; error) ,
123127 MissingDigits ( ref error) => write_err ! ( f, "the input has too few digits" ; error) ,
@@ -130,9 +134,9 @@ impl fmt::Display for ParseAmountError {
130134#[ cfg( feature = "std" ) ]
131135impl std:: error:: Error for ParseAmountError {
132136 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
133- use ParseAmountError :: * ;
137+ use ParseAmountErrorInner :: * ;
134138
135- match * self {
139+ match self . 0 {
136140 TooPrecise ( ref error) => Some ( error) ,
137141 InputTooLarge ( ref error) => Some ( error) ,
138142 OutOfRange ( ref error) => Some ( error) ,
@@ -199,7 +203,9 @@ impl fmt::Display for OutOfRangeError {
199203impl std:: error:: Error for OutOfRangeError { }
200204
201205impl From < OutOfRangeError > for ParseAmountError {
202- fn from ( value : OutOfRangeError ) -> Self { ParseAmountError :: OutOfRange ( value) }
206+ fn from ( value : OutOfRangeError ) -> Self {
207+ ParseAmountError ( ParseAmountErrorInner :: OutOfRange ( value) )
208+ }
203209}
204210
205211/// Error returned when the input string has higher precision than satoshis.
0 commit comments