@@ -1391,15 +1391,13 @@ fn fill_country_results(params: &Args) -> Result<(), Box<dyn std::error::Error>>
13911391 for result in & * data {
13921392 result. ipv4 . par_iter ( ) . for_each ( |( key, value) | {
13931393 let client_country = match geoip_reader
1394- . lookup :: < maxminddb:: geoip2:: Country > ( std:: net:: IpAddr :: V4 ( Ipv4Addr :: from ( * key) ) )
1394+ . lookup ( std:: net:: IpAddr :: V4 ( Ipv4Addr :: from ( * key) ) )
1395+ . and_then ( |r| r. decode :: < maxminddb:: geoip2:: Country > ( ) )
13951396 {
1396- Ok ( Some ( c) ) => match c. country {
1397- Some ( co) => match co. iso_code {
1398- Some ( iso) => iso. to_string ( ) ,
1399- _ => "N/A" . to_string ( ) ,
1400- } ,
1401- _ => "N/A" . to_string ( ) ,
1402- } ,
1397+ Ok ( Some ( c) ) => c
1398+ . country
1399+ . iso_code
1400+ . map_or ( "N/A" . to_string ( ) , |iso| iso. to_string ( ) ) ,
14031401 _ => "N/A" . to_string ( ) ,
14041402 } ;
14051403
@@ -1427,15 +1425,13 @@ fn fill_country_results(params: &Args) -> Result<(), Box<dyn std::error::Error>>
14271425 } ) ;
14281426 result. ipv6 . par_iter ( ) . for_each ( |( key, value) | {
14291427 let client_country = match geoip_reader
1430- . lookup :: < maxminddb:: geoip2:: Country > ( std:: net:: IpAddr :: V6 ( Ipv6Addr :: from ( * key) ) )
1428+ . lookup ( std:: net:: IpAddr :: V6 ( Ipv6Addr :: from ( * key) ) )
1429+ . and_then ( |r| r. decode :: < maxminddb:: geoip2:: Country > ( ) )
14311430 {
1432- Ok ( Some ( c) ) => match c. country {
1433- Some ( co) => match co. iso_code {
1434- Some ( iso) => iso. to_string ( ) ,
1435- _ => "N/A" . to_string ( ) ,
1436- } ,
1437- _ => "N/A" . to_string ( ) ,
1438- } ,
1431+ Ok ( Some ( c) ) => c
1432+ . country
1433+ . iso_code
1434+ . map_or ( "N/A" . to_string ( ) , |iso| iso. to_string ( ) ) ,
14391435 _ => "N/A" . to_string ( ) ,
14401436 } ;
14411437
0 commit comments