File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed
Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -615,16 +615,22 @@ impl FromStr for AddressPaginator {
615615 type Err = String ;
616616
617617 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
618- Txid :: from_hex ( s)
619- . ok ( )
620- . and_then ( |txid| Some ( Self :: Txid ( txid) ) )
621- . or_else ( || {
622- s. parse :: < usize > ( )
623- . ok ( )
624- . filter ( |& skip| skip != 0 ) // Don't allow 0 for Skip
625- . and_then ( |skip| Some ( Self :: Skip ( skip) ) )
626- } )
627- . ok_or ( "Invalid AddressPaginator" . to_string ( ) )
618+ // 1) Deal with Options in if else statement
619+ // to utilize filter for usize.
620+ // 2) 64 length usize doesn't exist,
621+ // and from_hex is expensive.
622+ if s. len ( ) == 64 {
623+ Txid :: from_hex ( s)
624+ . ok ( )
625+ . and_then ( |txid| Some ( Self :: Txid ( txid) ) )
626+ } else {
627+ s. parse :: < usize > ( )
628+ . ok ( )
629+ . filter ( |& skip| skip != 0 ) // Don't allow 0 for Skip
630+ . and_then ( |skip| Some ( Self :: Skip ( skip) ) )
631+ }
632+ // 3) Convert the return value of the if else statement into a Result.
633+ . ok_or ( "Invalid AddressPaginator" . to_string ( ) )
628634 }
629635}
630636
You can’t perform that action at this time.
0 commit comments