]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
geoip-db-tool: Fix clippy warnings
authorMicah Elizabeth Scott <beth@torproject.org>
Mon, 14 Aug 2023 20:04:51 +0000 (13:04 -0700)
committerMicah Elizabeth Scott <beth@torproject.org>
Tue, 15 Aug 2023 16:52:30 +0000 (09:52 -0700)
This fixes warnings found by clippy 0.1.71 on Rust 1.71.1

Tested this by doing a geoip update without committing changes.

scripts/maint/geoip/geoip-db-tool/src/db.rs
scripts/maint/geoip/geoip-db-tool/src/main.rs

index 316182d8237865d57f0de66e68b7b571597cd744..3d631a3f9867748cba6e2d00b288c90783645e5a 100644 (file)
@@ -13,9 +13,9 @@ where
 }
 
 pub enum AnyBlock {
-    NetBlock(NetBlock),
-    AsBlock(AsBlock),
-    OtherBlock,
+    Net(NetBlock),
+    As(AsBlock),
+    Other,
 }
 
 impl<I> BlockReader<I>
@@ -50,13 +50,13 @@ where
     fn get_block(&mut self) -> Option<std::io::Result<AnyBlock>> {
         let mut kv = HashMap::new();
 
-        while let Some(line) = self.iter.next() {
+        for line in self.iter.by_ref() {
             //dbg!(&line);
             if let Err(e) = line {
                 return Some(Err(e));
             }
             let line_orig = line.unwrap();
-            let line = line_orig.splitn(2, '#').next().unwrap().trim();
+            let line = line_orig.split('#').next().unwrap().trim();
             if line.is_empty() {
                 if kv.is_empty() {
                     continue;
@@ -80,13 +80,13 @@ where
             let asn = kv.get("aut-num").unwrap(); // XXXX handle error better
             assert!(asn.starts_with("AS"));
             let asn = asn[2..].parse().unwrap();
-            return Some(Ok(AnyBlock::AsBlock(AsBlock { name, asn })));
+            return Some(Ok(AnyBlock::As(AsBlock { name, asn })));
         }
 
         let net = if let Some(net) = kv.get("net") {
             net.parse().unwrap() //XXXX handle the error better.
         } else {
-            return Some(Ok(AnyBlock::OtherBlock));
+            return Some(Ok(AnyBlock::Other));
         };
 
         let asn = if let Some(asn) = kv.get("aut-num") {
@@ -113,7 +113,7 @@ where
         let is_anycast = is_true(kv.get("is-anycast-proxy"));
         let is_satellite = is_true(kv.get("is-satellite-provider"));
 
-        Some(Ok(AnyBlock::NetBlock(NetBlock {
+        Some(Ok(AnyBlock::Net(NetBlock {
             net,
             asn,
             cc,
index b255981aaef4ee7f61499e4367b8b60003d53eea..cbadd6623fe699c62ff8522cca24ddcbbdfd69c4 100644 (file)
@@ -152,8 +152,8 @@ fn convert(args: Args) -> std::io::Result<()> {
     // Read blocks, and then sort them by specificity and address.
     for nb in reader {
         match nb {
-            db::AnyBlock::AsBlock(a) => networks.push(a),
-            db::AnyBlock::NetBlock(n) => blocks.push(n),
+            db::AnyBlock::As(a) => networks.push(a),
+            db::AnyBlock::Net(n) => blocks.push(n),
             _ => {}
         }
     }