@@ -394,8 +394,24 @@ impl std::error::Error for PossiblyConfusingDenominationError {
394394/// An error consensus decoding an `Amount`.
395395#[ cfg( feature = "encoding" ) ]
396396#[ derive( Debug , Clone , PartialEq , Eq ) ]
397- #[ non_exhaustive]
398- pub enum AmountDecoderError {
397+ pub struct AmountDecoderError ( pub ( super ) AmountDecoderErrorInner ) ;
398+
399+ #[ cfg( feature = "encoding" ) ]
400+ impl AmountDecoderError {
401+ /// Constructs an EOF error.
402+ pub ( super ) fn eof ( e : encoding:: UnexpectedEofError ) -> Self {
403+ Self ( AmountDecoderErrorInner :: UnexpectedEof ( e) )
404+ }
405+
406+ /// Constructs an out of range (`Amount::from_sat`) error.
407+ pub ( super ) fn out_of_range ( e : OutOfRangeError ) -> Self {
408+ Self ( AmountDecoderErrorInner :: OutOfRange ( e) )
409+ }
410+ }
411+
412+ #[ cfg( feature = "encoding" ) ]
413+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
414+ pub ( super ) enum AmountDecoderErrorInner {
399415 /// Not enough bytes given to decoder.
400416 UnexpectedEof ( encoding:: UnexpectedEofError ) ,
401417 /// Decoded amount is too big.
@@ -407,27 +423,26 @@ impl From<Infallible> for AmountDecoderError {
407423 fn from ( never : Infallible ) -> Self { match never { } }
408424}
409425
410- #[ cfg( feature = "encoding" ) ]
411- impl From < encoding:: UnexpectedEofError > for AmountDecoderError {
412- fn from ( e : encoding:: UnexpectedEofError ) -> Self { Self :: UnexpectedEof ( e) }
413- }
414-
415426#[ cfg( feature = "encoding" ) ]
416427impl fmt:: Display for AmountDecoderError {
417428 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
418- match * self {
419- Self :: UnexpectedEof ( ref e) => write_err ! ( f, "decode error" ; e) ,
420- Self :: OutOfRange ( ref e) => write_err ! ( f, "decode error" ; e) ,
429+ use AmountDecoderErrorInner as E ;
430+
431+ match self . 0 {
432+ E :: UnexpectedEof ( ref e) => write_err ! ( f, "decode error" ; e) ,
433+ E :: OutOfRange ( ref e) => write_err ! ( f, "decode error" ; e) ,
421434 }
422435 }
423436}
424437
425438#[ cfg( all( feature = "std" , feature = "encoding" ) ) ]
426439impl std:: error:: Error for AmountDecoderError {
427440 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
428- match * self {
429- Self :: UnexpectedEof ( ref e) => Some ( e) ,
430- Self :: OutOfRange ( ref e) => Some ( e) ,
441+ use AmountDecoderErrorInner as E ;
442+
443+ match self . 0 {
444+ E :: UnexpectedEof ( ref e) => Some ( e) ,
445+ E :: OutOfRange ( ref e) => Some ( e) ,
431446 }
432447 }
433448}
0 commit comments