@@ -16,6 +16,8 @@ use core::{fmt, num, ops};
1616#[ cfg( all( test, mutate) ) ]
1717use mutagen:: mutate;
1818
19+ use crate :: write_err;
20+
1921/// Logarithm table of each bech32 element, as a power of alpha = Z.
2022///
2123/// Includes Q as 0 but this is false; you need to exclude Q because it has no discrete log. If we
@@ -317,12 +319,27 @@ pub enum Error {
317319}
318320
319321impl fmt:: Display for Error {
320- fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result { todo ! ( ) }
322+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
323+ use Error :: * ;
324+
325+ match * self {
326+ NotAByte ( ref e) => write_err ! ( f, "invalid field element" ; e) ,
327+ InvalidByte ( ref b) => write ! ( f, "invalid byte in field element: {:#04x}" , b) ,
328+ InvalidChar ( ref c) => write ! ( f, "invalid char in field element: {}" , c) ,
329+ }
330+ }
321331}
322332
323333#[ cfg( feature = "std" ) ]
324334impl std:: error:: Error for Error {
325- fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > { todo ! ( ) }
335+ fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
336+ use Error :: * ;
337+
338+ match * self {
339+ NotAByte ( ref e) => Some ( e) ,
340+ InvalidByte ( _) | InvalidChar ( _) => None ,
341+ }
342+ }
326343}
327344
328345impl From < num:: TryFromIntError > for Error {
0 commit comments