From 965bcf3cc872eb83bd3108d294a5642541beff1b Mon Sep 17 00:00:00 2001 From: Neshura Date: Wed, 27 Dec 2023 21:07:15 +0100 Subject: [PATCH] Clippy linting --- src/config.rs | 3 +-- src/main.rs | 50 +++++++++++++++++++++++--------------------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2920855..e7bf385 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,8 +45,7 @@ impl InterfaceConfig { return Err(()); } }; - let interface_ip = host_range.bitor(interface_address); - Ok(interface_ip) + Ok(host_range.bitor(interface_address)) } } diff --git a/src/main.rs b/src/main.rs index b5753e5..259d2f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use reqwest::blocking::get; use std::{thread::{sleep}}; use std::error::Error; -use std::fmt::format; use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use chrono::{Utc, Duration}; @@ -156,7 +155,6 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec { if old_zone.entries != new_zone.entries { let mut added: Vec<&ZoneEntry> = vec![]; - let mut deleted: Vec<&ZoneEntry>; let mut modified: Vec<&ZoneEntry> = vec![]; new_zone.entries.iter().for_each(|entry| { @@ -172,17 +170,17 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec { } }).collect(); - if matches.len() == 0 { + if matches.is_empty() { added.push(entry); } }); - deleted = old_zone.entries.iter().filter(|old_entry| { + let deleted: Vec<&ZoneEntry> = old_zone.entries.iter().filter(|old_entry| { !new_zone.entries.contains(old_entry) && - new_zone.entries.iter().find(|changed_entry| { changed_entry.name == old_entry.name }).is_none() + !new_zone.entries.iter().any(|changed_entry| { changed_entry.name == old_entry.name }) }).collect(); - if deleted.len() != 0 { + if !deleted.is_empty() { let mut deleted_entries_vec = vec![]; for entry in deleted { @@ -198,7 +196,7 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec { info_pieces.push(msg); } - if added.len() != 0 { + if !added.is_empty() { let mut added_entries_vec = vec![]; for entry in added { @@ -214,7 +212,7 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec { info_pieces.push(msg); } - if modified.len() != 0 { + if !modified.is_empty() { let mut modified_entries_vec = vec![]; for entry in modified { @@ -268,7 +266,6 @@ fn main() { if ifaces.interfaces != new_cfg.interfaces { let mut new: Vec<(&String, &Ipv6Addr)> = vec![]; - let deleted: Vec<(&String, &Ipv6Addr)>; let mut modified: Vec<(&String, &Ipv6Addr)> = vec![]; new_cfg.interfaces.iter().for_each(|(interface, address)| { @@ -279,10 +276,10 @@ fn main() { } else { let matches: Vec<&Ipv6Addr> = ifaces.interfaces.values().filter(|addr| { - *addr == address + addr == &address }).collect(); - if matches.len() == 0 { + if matches.is_empty() { new.push((interface, address)); } else { @@ -291,8 +288,8 @@ fn main() { } }); - deleted = ifaces.interfaces.iter().filter(|(interface, address)| { - !new_cfg.interfaces.contains_key(*interface) && modified.iter().find(|(_, new_addr)| { new_addr == address }).is_none() + let deleted: Vec<(&String, &Ipv6Addr)> = ifaces.interfaces.iter().filter(|(interface, address)| { + !new_cfg.interfaces.contains_key(*interface) && !modified.iter().any(|(_, new_addr)| { new_addr == address }) }).collect(); for (name, addr) in deleted { @@ -312,18 +309,17 @@ fn main() { } for (name, addr) in modified { - let info_msg; - if ifaces.interfaces.contains_key(name) { + let info_msg= if ifaces.interfaces.contains_key(name) { let old_addr = ifaces.interfaces.get(name).expect("contains check on ifaces was successful"); - info_msg = format!("Changed interface address of '{name}' from '{old_addr}' to '{addr}'"); + format!("Changed interface address of '{name}' from '{old_addr}' to '{addr}'") } else { let old_name = ifaces.interfaces.iter() .find(|(_, old_addr)| { old_addr == &addr }) .expect("modified entry should not exist if this fails") .0; - info_msg = format!("Changed interface name for '{addr}' from '{old_name}' to '{name}'"); - } + format!("Changed interface name for '{addr}' from '{old_name}' to '{name}'") + }; match connected_to_journal() { true => info!("[INFO] {info_msg}"), @@ -379,21 +375,21 @@ fn main() { } else { let changed_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| { - zone_cfgs.iter().find(|old_cfg| { - old_cfg.name == new_cfg.name && old_cfg != new_cfg - }).is_some() + zone_cfgs.iter().any(|old_cfg| { + old_cfg.name == new_cfg.name && &old_cfg != new_cfg + }) }).collect(); let deleted_zones: Vec<&ZoneConfig> = zone_cfgs.iter().filter(|old_cfg| { - new_cfgs.iter().find(|new_cfg| { + !new_cfgs.iter().any(|new_cfg| { old_cfg.name == new_cfg.name - }).is_none() + }) }).collect(); let added_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| { - zone_cfgs.iter().find(|old_cfg| { + !zone_cfgs.iter().any(|old_cfg| { old_cfg.name == new_cfg.name - }).is_none() + }) }).collect(); if deleted_zones.len() == 1 && added_zones.len() == 1 { @@ -412,7 +408,7 @@ fn main() { println!("{}", info_pieces.join(", ")); } else { - if deleted_zones.len() != 0 { + if !deleted_zones.is_empty() { let mut info_pieces = vec![]; for deleted_zone in deleted_zones { info_pieces.push(deleted_zone.name.clone()); @@ -429,7 +425,7 @@ fn main() { } } - if added_zones.len() != 0 { + if !added_zones.is_empty() { let mut info_pieces = vec![]; for added_zone in added_zones { info_pieces.push(added_zone.name.clone());