@@ -11,8 +11,10 @@ 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 ) ,
1820 /// Invalid denomination.
@@ -22,42 +24,43 @@ pub enum ParseError {
2224}
2325
2426internals:: impl_from_infallible!( ParseError ) ;
27+ internals:: impl_from_infallible!( ParseErrorInner ) ;
2528
2629impl From < ParseAmountError > for ParseError {
27- fn from ( e : ParseAmountError ) -> Self { Self :: Amount ( e) }
30+ fn from ( e : ParseAmountError ) -> Self { Self ( ParseErrorInner :: Amount ( e) ) }
2831}
2932
3033impl From < ParseDenominationError > for ParseError {
31- fn from ( e : ParseDenominationError ) -> Self { Self :: Denomination ( e) }
34+ fn from ( e : ParseDenominationError ) -> Self { Self ( ParseErrorInner :: Denomination ( e) ) }
3235}
3336
3437impl From < OutOfRangeError > for ParseError {
35- fn from ( e : OutOfRangeError ) -> Self { Self :: Amount ( e. into ( ) ) }
38+ fn from ( e : OutOfRangeError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
3639}
3740
3841impl From < TooPreciseError > for ParseError {
39- fn from ( e : TooPreciseError ) -> Self { Self :: Amount ( e. into ( ) ) }
42+ fn from ( e : TooPreciseError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
4043}
4144
4245impl From < MissingDigitsError > for ParseError {
43- fn from ( e : MissingDigitsError ) -> Self { Self :: Amount ( e. into ( ) ) }
46+ fn from ( e : MissingDigitsError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
4447}
4548
4649impl From < InputTooLargeError > for ParseError {
47- fn from ( e : InputTooLargeError ) -> Self { Self :: Amount ( e. into ( ) ) }
50+ fn from ( e : InputTooLargeError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
4851}
4952
5053impl From < InvalidCharacterError > for ParseError {
51- fn from ( e : InvalidCharacterError ) -> Self { Self :: Amount ( e. into ( ) ) }
54+ fn from ( e : InvalidCharacterError ) -> Self { Self ( ParseErrorInner :: Amount ( e. into ( ) ) ) }
5255}
5356
5457impl fmt:: Display for ParseError {
5558 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
56- match self {
57- ParseError :: Amount ( error ) => write_err ! ( f, "invalid amount" ; error ) ,
58- ParseError :: Denomination ( error ) => write_err ! ( f, "invalid denomination" ; error ) ,
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 ) ,
5962 // We consider this to not be a source because it currently doesn't contain useful info.
60- ParseError :: MissingDenomination ( _) =>
63+ ParseErrorInner :: MissingDenomination ( _) =>
6164 f. write_str ( "the input doesn't contain a denomination" ) ,
6265 }
6366 }
@@ -66,19 +69,21 @@ impl fmt::Display for ParseError {
6669#[ cfg( feature = "std" ) ]
6770impl std:: error:: Error for ParseError {
6871 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
69- match self {
70- ParseError :: Amount ( error ) => Some ( error ) ,
71- ParseError :: Denomination ( error ) => Some ( error ) ,
72+ match self . 0 {
73+ ParseErrorInner :: Amount ( ref e ) => Some ( e ) ,
74+ ParseErrorInner :: Denomination ( ref e ) => Some ( e ) ,
7275 // We consider this to not be a source because it currently doesn't contain useful info.
73- ParseError :: MissingDenomination ( _) => None ,
76+ ParseErrorInner :: MissingDenomination ( _) => None ,
7477 }
7578 }
7679}
7780
7881/// An error during amount parsing.
7982#[ derive( Debug , Clone , PartialEq , Eq ) ]
80- #[ non_exhaustive]
81- pub enum ParseAmountError {
83+ pub struct ParseAmountError ( pub ( crate ) ParseAmountErrorInner ) ;
84+
85+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
86+ pub ( crate ) enum ParseAmountErrorInner {
8287 /// The amount is too big or too small.
8388 OutOfRange ( OutOfRangeError ) ,
8489 /// Amount has higher precision than supported by the type.
@@ -92,28 +97,31 @@ pub enum ParseAmountError {
9297}
9398
9499impl From < TooPreciseError > for ParseAmountError {
95- fn from ( value : TooPreciseError ) -> Self { Self :: TooPrecise ( value) }
100+ fn from ( value : TooPreciseError ) -> Self { Self ( ParseAmountErrorInner :: TooPrecise ( value) ) }
96101}
97102
98103impl From < MissingDigitsError > for ParseAmountError {
99- fn from ( value : MissingDigitsError ) -> Self { Self :: MissingDigits ( value) }
104+ fn from ( value : MissingDigitsError ) -> Self { Self ( ParseAmountErrorInner :: MissingDigits ( value) ) }
100105}
101106
102107impl From < InputTooLargeError > for ParseAmountError {
103- fn from ( value : InputTooLargeError ) -> Self { Self :: InputTooLarge ( value) }
108+ fn from ( value : InputTooLargeError ) -> Self { Self ( ParseAmountErrorInner :: InputTooLarge ( value) ) }
104109}
105110
106111impl From < InvalidCharacterError > for ParseAmountError {
107- fn from ( value : InvalidCharacterError ) -> Self { Self :: InvalidCharacter ( value) }
112+ fn from ( value : InvalidCharacterError ) -> Self {
113+ Self ( ParseAmountErrorInner :: InvalidCharacter ( value) )
114+ }
108115}
109116
110117internals:: impl_from_infallible!( ParseAmountError ) ;
118+ internals:: impl_from_infallible!( ParseAmountErrorInner ) ;
111119
112120impl fmt:: Display for ParseAmountError {
113121 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
114- use ParseAmountError :: * ;
122+ use ParseAmountErrorInner :: * ;
115123
116- match * self {
124+ match self . 0 {
117125 OutOfRange ( ref error) => write_err ! ( f, "amount out of range" ; error) ,
118126 TooPrecise ( ref error) => write_err ! ( f, "amount has a too high precision" ; error) ,
119127 MissingDigits ( ref error) => write_err ! ( f, "the input has too few digits" ; error) ,
@@ -126,9 +134,9 @@ impl fmt::Display for ParseAmountError {
126134#[ cfg( feature = "std" ) ]
127135impl std:: error:: Error for ParseAmountError {
128136 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
129- use ParseAmountError :: * ;
137+ use ParseAmountErrorInner :: * ;
130138
131- match * self {
139+ match self . 0 {
132140 TooPrecise ( ref error) => Some ( error) ,
133141 InputTooLarge ( ref error) => Some ( error) ,
134142 OutOfRange ( ref error) => Some ( error) ,
@@ -195,7 +203,9 @@ impl fmt::Display for OutOfRangeError {
195203impl std:: error:: Error for OutOfRangeError { }
196204
197205impl From < OutOfRangeError > for ParseAmountError {
198- fn from ( value : OutOfRangeError ) -> Self { ParseAmountError :: OutOfRange ( value) }
206+ fn from ( value : OutOfRangeError ) -> Self {
207+ ParseAmountError ( ParseAmountErrorInner :: OutOfRange ( value) )
208+ }
199209}
200210
201211/// Error returned when the input string has higher precision than satoshis.
0 commit comments