@@ -138,15 +138,15 @@ impl<'s> UncheckedHrpstring<'s> {
138138 /// checksum if `NoChecksum` is used).
139139 #[ inline]
140140 pub fn validate_checksum < Ck : Checksum > ( & self ) -> Result < ( ) , ChecksumError > {
141- use ChecksumError :: * ;
141+ use ChecksumError as E ;
142142
143143 if Ck :: CHECKSUM_LENGTH == 0 {
144144 // Called with NoChecksum
145145 return Ok ( ( ) ) ;
146146 }
147147
148148 if self . data . len ( ) < Ck :: CHECKSUM_LENGTH {
149- return Err ( InvalidChecksumLength ) ;
149+ return Err ( E :: InvalidChecksumLength ) ;
150150 }
151151
152152 let mut checksum_eng = checksum:: Engine :: < Ck > :: new ( ) ;
@@ -158,7 +158,7 @@ impl<'s> UncheckedHrpstring<'s> {
158158 }
159159
160160 if checksum_eng. residue ( ) != & Ck :: TARGET_RESIDUE {
161- return Err ( InvalidChecksum ) ;
161+ return Err ( E :: InvalidChecksum ) ;
162162 }
163163
164164 Ok ( ( ) )
@@ -405,7 +405,7 @@ impl<'s> SegwitHrpstring<'s> {
405405///
406406/// The byte-index into the string where the '1' separator occurs, or an error if it does not.
407407fn check_characters ( s : & str ) -> Result < usize , CharError > {
408- use CharError :: * ;
408+ use CharError as E ;
409409
410410 let mut has_upper = false ;
411411 let mut has_lower = false ;
@@ -417,7 +417,7 @@ fn check_characters(s: &str) -> Result<usize, CharError> {
417417 sep_pos = Some ( n) ;
418418 }
419419 if req_bech32 {
420- Fe32 :: from_char ( ch) . map_err ( |_| InvalidChar ( ch) ) ?;
420+ Fe32 :: from_char ( ch) . map_err ( |_| E :: InvalidChar ( ch) ) ?;
421421 }
422422 if ch. is_ascii_uppercase ( ) {
423423 has_upper = true ;
@@ -426,11 +426,11 @@ fn check_characters(s: &str) -> Result<usize, CharError> {
426426 }
427427 }
428428 if has_upper && has_lower {
429- Err ( MixedCase )
429+ Err ( E :: MixedCase )
430430 } else if let Some ( pos) = sep_pos {
431431 Ok ( pos)
432432 } else {
433- Err ( MissingSeparator )
433+ Err ( E :: MissingSeparator )
434434 }
435435}
436436
@@ -505,29 +505,25 @@ pub enum SegwitHrpstringError {
505505
506506impl fmt:: Display for SegwitHrpstringError {
507507 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
508- use SegwitHrpstringError :: * ;
509-
510508 match * self {
511- Unchecked ( ref e) => write_err ! ( f, "parsing unchecked hrpstring failed" ; e) ,
512- MissingWitnessVersion => write ! ( f, "the witness version byte is missing" ) ,
513- InvalidWitnessVersion ( fe) => write ! ( f, "invalid segwit witness version: {}" , fe. to_u8( ) ) ,
514- Padding ( ref e) => write_err ! ( f, "invalid padding on the witness data" ; e) ,
515- WitnessLength ( ref e) => write_err ! ( f, "invalid witness length" ; e) ,
516- Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
509+ Self :: Unchecked ( ref e) => write_err ! ( f, "parsing unchecked hrpstring failed" ; e) ,
510+ Self :: MissingWitnessVersion => write ! ( f, "the witness version byte is missing" ) ,
511+ Self :: InvalidWitnessVersion ( fe) => write ! ( f, "invalid segwit witness version: {}" , fe. to_u8( ) ) ,
512+ Self :: Padding ( ref e) => write_err ! ( f, "invalid padding on the witness data" ; e) ,
513+ Self :: WitnessLength ( ref e) => write_err ! ( f, "invalid witness length" ; e) ,
514+ Self :: Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
517515 }
518516 }
519517}
520518
521519impl std:: error:: Error for SegwitHrpstringError {
522520 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
523- use SegwitHrpstringError :: * ;
524-
525521 match * self {
526- Unchecked ( ref e) => Some ( e) ,
527- Padding ( ref e) => Some ( e) ,
528- WitnessLength ( ref e) => Some ( e) ,
529- Checksum ( ref e) => Some ( e) ,
530- MissingWitnessVersion | InvalidWitnessVersion ( _) => None ,
522+ Self :: Unchecked ( ref e) => Some ( e) ,
523+ Self :: Padding ( ref e) => Some ( e) ,
524+ Self :: WitnessLength ( ref e) => Some ( e) ,
525+ Self :: Checksum ( ref e) => Some ( e) ,
526+ Self :: MissingWitnessVersion | Self :: InvalidWitnessVersion ( _) => None ,
531527 }
532528 }
533529}
@@ -564,22 +560,18 @@ pub enum CheckedHrpstringError {
564560
565561impl fmt:: Display for CheckedHrpstringError {
566562 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
567- use CheckedHrpstringError :: * ;
568-
569563 match * self {
570- Parse ( ref e) => write_err ! ( f, "parse failed" ; e) ,
571- Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
564+ Self :: Parse ( ref e) => write_err ! ( f, "parse failed" ; e) ,
565+ Self :: Checksum ( ref e) => write_err ! ( f, "invalid checksum" ; e) ,
572566 }
573567 }
574568}
575569
576570impl std:: error:: Error for CheckedHrpstringError {
577571 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
578- use CheckedHrpstringError :: * ;
579-
580572 match * self {
581- Parse ( ref e) => Some ( e) ,
582- Checksum ( ref e) => Some ( e) ,
573+ Self :: Parse ( ref e) => Some ( e) ,
574+ Self :: Checksum ( ref e) => Some ( e) ,
583575 }
584576 }
585577}
@@ -606,22 +598,18 @@ pub enum UncheckedHrpstringError {
606598
607599impl fmt:: Display for UncheckedHrpstringError {
608600 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
609- use UncheckedHrpstringError :: * ;
610-
611601 match * self {
612- Char ( ref e) => write_err ! ( f, "character error" ; e) ,
613- Hrp ( ref e) => write_err ! ( f, "invalid human-readable part" ; e) ,
602+ Self :: Char ( ref e) => write_err ! ( f, "character error" ; e) ,
603+ Self :: Hrp ( ref e) => write_err ! ( f, "invalid human-readable part" ; e) ,
614604 }
615605 }
616606}
617607
618608impl std:: error:: Error for UncheckedHrpstringError {
619609 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
620- use UncheckedHrpstringError :: * ;
621-
622610 match * self {
623- Char ( ref e) => Some ( e) ,
624- Hrp ( ref e) => Some ( e) ,
611+ Self :: Char ( ref e) => Some ( e) ,
612+ Self :: Hrp ( ref e) => Some ( e) ,
625613 }
626614 }
627615}
@@ -656,30 +644,26 @@ pub enum CharError {
656644
657645impl fmt:: Display for CharError {
658646 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
659- use CharError :: * ;
660-
661647 match * self {
662- MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
663- NothingAfterSeparator => write ! ( f, "invalid data - no characters after the separator" ) ,
664- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
665- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
666- InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
667- MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
648+ Self :: MissingSeparator => write ! ( f, "missing human-readable separator, \" {}\" " , SEP ) ,
649+ Self :: NothingAfterSeparator => write ! ( f, "invalid data - no characters after the separator" ) ,
650+ Self :: InvalidChecksum => write ! ( f, "invalid checksum" ) ,
651+ Self :: InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
652+ Self :: InvalidChar ( n) => write ! ( f, "invalid character (code={})" , n) ,
653+ Self :: MixedCase => write ! ( f, "mixed-case strings not allowed" ) ,
668654 }
669655 }
670656}
671657
672658impl std:: error:: Error for CharError {
673659 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
674- use CharError :: * ;
675-
676660 match * self {
677- MissingSeparator
678- | NothingAfterSeparator
679- | InvalidChecksum
680- | InvalidChecksumLength
681- | InvalidChar ( _)
682- | MixedCase => None ,
661+ Self :: MissingSeparator
662+ | Self :: NothingAfterSeparator
663+ | Self :: InvalidChecksum
664+ | Self :: InvalidChecksumLength
665+ | Self :: InvalidChar ( _)
666+ | Self :: MixedCase => None ,
683667 }
684668 }
685669}
@@ -696,21 +680,17 @@ pub enum ChecksumError {
696680
697681impl fmt:: Display for ChecksumError {
698682 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
699- use ChecksumError :: * ;
700-
701683 match * self {
702- InvalidChecksum => write ! ( f, "invalid checksum" ) ,
703- InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
684+ Self :: InvalidChecksum => write ! ( f, "invalid checksum" ) ,
685+ Self :: InvalidChecksumLength => write ! ( f, "the checksum is not a valid length" ) ,
704686 }
705687 }
706688}
707689
708690impl std:: error:: Error for ChecksumError {
709691 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
710- use ChecksumError :: * ;
711-
712692 match * self {
713- InvalidChecksum | InvalidChecksumLength => None ,
693+ Self :: InvalidChecksum | Self :: InvalidChecksumLength => None ,
714694 }
715695 }
716696}
@@ -727,21 +707,17 @@ pub enum PaddingError {
727707
728708impl fmt:: Display for PaddingError {
729709 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
730- use PaddingError :: * ;
731-
732710 match * self {
733- TooMuch => write ! ( f, "the data payload has too many bits of padding" ) ,
734- NonZero => write ! ( f, "the data payload is padded with non-zero bits" ) ,
711+ Self :: TooMuch => write ! ( f, "the data payload has too many bits of padding" ) ,
712+ Self :: NonZero => write ! ( f, "the data payload is padded with non-zero bits" ) ,
735713 }
736714 }
737715}
738716
739717impl std:: error:: Error for PaddingError {
740718 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
741- use PaddingError :: * ;
742-
743719 match * self {
744- TooMuch | NonZero => None ,
720+ Self :: TooMuch | Self :: NonZero => None ,
745721 }
746722 }
747723}
@@ -752,32 +728,32 @@ mod tests {
752728
753729 #[ test]
754730 fn bip_173_invalid_parsing_fails ( ) {
755- use UncheckedHrpstringError :: * ;
731+ use UncheckedHrpstringError as E ;
756732
757733 let invalid: Vec < ( & str , UncheckedHrpstringError ) > = vec ! (
758734 ( "\u{20} 1nwldj5" ,
759735 // TODO: Rust >= 1.59.0 use Hrp(hrp::Error::InvalidAsciiByte('\u{20}'.try_into().unwrap()))),
760- Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
736+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
761737 ( "\u{7F} 1axkwrx" ,
762- Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
738+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
763739 ( "\u{80} 1eym55h" ,
764- Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
740+ E :: Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
765741 ( "an84characterslonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11d6pts4" ,
766- Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
742+ E :: Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
767743 ( "pzry9x0s0muk" ,
768- Char ( CharError :: MissingSeparator ) ) ,
744+ E :: Char ( CharError :: MissingSeparator ) ) ,
769745 ( "1pzry9x0s0muk" ,
770- Hrp ( hrp:: Error :: Empty ) ) ,
746+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
771747 ( "x1b4n0q5v" ,
772- Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
748+ E :: Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
773749 // "li1dgmt3" in separate test because error is a checksum error.
774750 ( "de1lg7wt\u{ff} " ,
775- Char ( CharError :: InvalidChar ( '\u{ff}' ) ) ) ,
751+ E :: Char ( CharError :: InvalidChar ( '\u{ff}' ) ) ) ,
776752 // "A1G7SGD8" in separate test because error is a checksum error.
777753 ( "10a06t8" ,
778- Hrp ( hrp:: Error :: Empty ) ) ,
754+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
779755 ( "1qzzfhee" ,
780- Hrp ( hrp:: Error :: Empty ) ) ,
756+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
781757 ) ;
782758
783759 for ( s, want) in invalid {
@@ -789,54 +765,54 @@ mod tests {
789765 /*
790766 #[test]
791767 fn bip_173_invalid_parsing_fails_invalid_checksum() {
792- use ChecksumError::* ;
768+ use ChecksumError as E ;
793769
794770 let err = UncheckedHrpstring::new("li1dgmt3")
795771 .expect("string parses correctly")
796772 .validate_checksum::<Blech32>()
797773 .unwrap_err();
798- assert_eq!(err, InvalidChecksumLength);
774+ assert_eq!(err, E:: InvalidChecksumLength);
799775
800776 let err = UncheckedHrpstring::new("A1G7SGD8")
801777 .expect("string parses correctly")
802778 .validate_checksum::<Blech32>()
803779 .unwrap_err();
804- assert_eq!(err, InvalidChecksum);
780+ assert_eq!(err, E:: InvalidChecksum);
805781 }
806782 */
807783
808784 #[ test]
809785 fn bip_350_invalid_parsing_fails ( ) {
810- use UncheckedHrpstringError :: * ;
786+ use UncheckedHrpstringError as E ;
811787
812788 let invalid: Vec < ( & str , UncheckedHrpstringError ) > = vec ! (
813789 ( "\u{20} 1xj0phk" ,
814790 // TODO: Rust >= 1.59.0 use Hrp(hrp::Error::InvalidAsciiByte('\u{20}'.try_into().unwrap()))),
815- Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
791+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 32 ) ) ) ,
816792 ( "\u{7F} 1g6xzxy" ,
817- Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
793+ E :: Hrp ( hrp:: Error :: InvalidAsciiByte ( 127 ) ) ) ,
818794 ( "\u{80} 1g6xzxy" ,
819- Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
795+ E :: Hrp ( hrp:: Error :: NonAsciiChar ( '\u{80}' ) ) ) ,
820796 ( "an84characterslonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1569pvx" ,
821- Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
797+ E :: Hrp ( hrp:: Error :: TooLong ( 84 ) ) ) ,
822798 ( "qyrz8wqd2c9m" ,
823- Char ( CharError :: MissingSeparator ) ) ,
799+ E :: Char ( CharError :: MissingSeparator ) ) ,
824800 ( "1qyrz8wqd2c9m" ,
825- Hrp ( hrp:: Error :: Empty ) ) ,
801+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
826802 ( "y1b0jsk6g" ,
827- Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
803+ E :: Char ( CharError :: InvalidChar ( 'b' ) ) ) ,
828804 ( "lt1igcx5c0" ,
829- Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
805+ E :: Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
830806 // "in1muywd" in separate test because error is a checksum error.
831807 ( "mm1crxm3i" ,
832- Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
808+ E :: Char ( CharError :: InvalidChar ( 'i' ) ) ) ,
833809 ( "au1s5cgom" ,
834- Char ( CharError :: InvalidChar ( 'o' ) ) ) ,
810+ E :: Char ( CharError :: InvalidChar ( 'o' ) ) ) ,
835811 // "M1VUXWEZ" in separate test because error is a checksum error.
836812 ( "16plkw9" ,
837- Hrp ( hrp:: Error :: Empty ) ) ,
813+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
838814 ( "1p2gdwpf" ,
839- Hrp ( hrp:: Error :: Empty ) ) ,
815+ E :: Hrp ( hrp:: Error :: Empty ) ) ,
840816
841817 ) ;
842818
0 commit comments