@@ -137,8 +137,9 @@ impl fmt::Display for ParseAmountError {
137137 E :: TooPrecise ( ref error) => write_err ! ( f, "amount has a too high precision" ; error) ,
138138 E :: MissingDigits ( ref error) => write_err ! ( f, "the input has too few digits" ; error) ,
139139 E :: InputTooLarge ( ref error) => write_err ! ( f, "the input is too large" ; error) ,
140- E :: InvalidCharacter ( ref error) =>
141- write_err ! ( f, "invalid character in the input" ; error) ,
140+ E :: InvalidCharacter ( ref error) => {
141+ write_err ! ( f, "invalid character in the input" ; error)
142+ }
142143 }
143144 }
144145}
@@ -389,3 +390,44 @@ impl fmt::Display for PossiblyConfusingDenominationError {
389390impl std:: error:: Error for PossiblyConfusingDenominationError {
390391 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > { None }
391392}
393+
394+ /// An error consensus decoding an `Amount`.
395+ #[ cfg( feature = "encoding" ) ]
396+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
397+ #[ non_exhaustive]
398+ pub enum AmountDecoderError {
399+ /// Not enough bytes given to decoder.
400+ UnexpectedEof ( encoding:: UnexpectedEofError ) ,
401+ /// Decoded amount is too big.
402+ OutOfRange ( OutOfRangeError ) ,
403+ }
404+
405+ #[ cfg( feature = "encoding" ) ]
406+ impl From < Infallible > for AmountDecoderError {
407+ fn from ( never : Infallible ) -> Self { match never { } }
408+ }
409+
410+ #[ cfg( feature = "encoding" ) ]
411+ impl From < encoding:: UnexpectedEofError > for AmountDecoderError {
412+ fn from ( e : encoding:: UnexpectedEofError ) -> Self { Self :: UnexpectedEof ( e) }
413+ }
414+
415+ #[ cfg( feature = "encoding" ) ]
416+ impl fmt:: Display for AmountDecoderError {
417+ 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) ,
421+ }
422+ }
423+ }
424+
425+ #[ cfg( all( feature = "std" , feature = "encoding" ) ) ]
426+ impl std:: error:: Error for AmountDecoderError {
427+ 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) ,
431+ }
432+ }
433+ }
0 commit comments