@@ -16,6 +16,8 @@ use core::{fmt, num, ops};
16
16
#[ cfg( all( test, mutate) ) ]
17
17
use mutagen:: mutate;
18
18
19
+ use crate :: write_err;
20
+
19
21
/// Logarithm table of each bech32 element, as a power of alpha = Z.
20
22
///
21
23
/// 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 {
317
319
}
318
320
319
321
impl 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
+ }
321
331
}
322
332
323
333
#[ cfg( feature = "std" ) ]
324
334
impl 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
+ }
326
343
}
327
344
328
345
impl From < num:: TryFromIntError > for Error {
0 commit comments