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 @@ -613,16 +613,22 @@ impl FromStr for AddressPaginator {
613613 type Err = String ;
614614
615615 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
616- Txid :: from_hex ( s)
617- . ok ( )
618- . and_then ( |txid| Some ( Self :: Txid ( txid) ) )
619- . or_else ( || {
620- s. parse :: < usize > ( )
621- . ok ( )
622- . filter ( |& skip| skip != 0 ) // Don't allow 0 for Skip
623- . and_then ( |skip| Some ( Self :: Skip ( skip) ) )
624- } )
625- . ok_or ( "Invalid AddressPaginator" . to_string ( ) )
616+ // 1) Deal with Options in if else statement
617+ // to utilize filter for usize.
618+ // 2) 64 length usize doesn't exist,
619+ // and from_hex is expensive.
620+ if s. len ( ) == 64 {
621+ Txid :: from_hex ( s)
622+ . ok ( )
623+ . and_then ( |txid| Some ( Self :: Txid ( txid) ) )
624+ } else {
625+ s. parse :: < usize > ( )
626+ . ok ( )
627+ . filter ( |& skip| skip != 0 ) // Don't allow 0 for Skip
628+ . and_then ( |skip| Some ( Self :: Skip ( skip) ) )
629+ }
630+ // 3) Convert the return value of the if else statement into a Result.
631+ . ok_or ( "Invalid AddressPaginator" . to_string ( ) )
626632 }
627633}
628634
You can’t perform that action at this time.
0 commit comments