From f27a2426c8db246eb7542cdb32beeea880ee4baf Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Thu, 6 May 2021 12:40:00 +0900 Subject: [PATCH] client: make clippy happy --- client/src/main.rs | 10 +++++----- hostsfile/src/lib.rs | 6 +++--- shared/src/types.rs | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 27e5b2a..360ad63 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -187,7 +187,7 @@ impl std::error::Error for ClientError { fn update_hosts_file( interface: &InterfaceName, hosts_path: PathBuf, - peers: &Vec, + peers: &[Peer], ) -> Result<(), Error> { println!( "{} updating {} with the latest peers.", @@ -445,7 +445,7 @@ fn fetch( for peer in existing_peers { let public_key = peer.config.public_key.to_base64(); - if peers.iter().find(|p| p.public_key == public_key).is_none() { + if !peers.iter().any(|p| p.public_key == public_key) { println!( " peer ({}...) was {}.", &public_key[..10].yellow(), @@ -712,7 +712,7 @@ fn override_endpoint(interface: &InterfaceName, unset: bool) -> Result<(), Error fn show(short: bool, tree: bool, interface: Option) -> Result<(), Error> { let interfaces = - interface.map_or_else(|| DeviceInfo::enumerate(), |interface| Ok(vec![*interface]))?; + interface.map_or_else(DeviceInfo::enumerate, |interface| Ok(vec![*interface]))?; let devices = interfaces.into_iter().filter_map(|name| { DataStore::open(&name) @@ -744,7 +744,7 @@ fn show(short: bool, tree: bool, interface: Option) -> Result<(), Err }); if tree { - let cidr_tree = CidrTree::new(&cidrs[..]); + let cidr_tree = CidrTree::new(cidrs); print_tree(&cidr_tree, &peers, 1); } else { for peer in device_info.peers { @@ -769,7 +769,7 @@ fn print_tree(cidr: &CidrTree, peers: &[Peer], level: usize) { ); let mut children: Vec<_> = cidr.children().collect(); - children.sort_by(|a, b| a.cmp(&b)); + children.sort(); children .iter() .for_each(|child| print_tree(&child, peers, level + 1)); diff --git a/hostsfile/src/lib.rs b/hostsfile/src/lib.rs index f22ae40..437867b 100644 --- a/hostsfile/src/lib.rs +++ b/hostsfile/src/lib.rs @@ -88,7 +88,7 @@ impl HostsBuilder { /// Adds a mapping of `ip` to `hostname`. If there hostnames associated with the IP already, /// the hostname will be appended to the list. pub fn add_hostname(&mut self, ip: IpAddr, hostname: S) { - let hostnames_dest = self.hostname_map.entry(ip.into()).or_insert(Vec::new()); + let hostnames_dest = self.hostname_map.entry(ip).or_insert_with(Vec::new); hostnames_dest.push(hostname.to_string()); } @@ -99,7 +99,7 @@ impl HostsBuilder { ip: IpAddr, hostnames: I, ) { - let hostnames_dest = self.hostname_map.entry(ip.into()).or_insert(Vec::new()); + let hostnames_dest = self.hostname_map.entry(ip).or_insert_with(Vec::new); for hostname in hostnames.into_iter() { hostnames_dest.push(hostname.to_string()); } @@ -153,7 +153,7 @@ impl HostsBuilder { (None, None) => { // Insert a blank line before a new section. if let Some(last_line) = lines.iter().last() { - if last_line != "" { + if !last_line.is_empty() { lines.push("".to_string()); } } diff --git a/shared/src/types.rs b/shared/src/types.rs index 139dede..2072dc3 100644 --- a/shared/src/types.rs +++ b/shared/src/types.rs @@ -176,7 +176,7 @@ impl Deref for Association { } } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, PartialOrd, Eq, Ord)] pub struct CidrContents { pub name: String, pub cidr: IpNetwork, @@ -191,7 +191,7 @@ impl Deref for CidrContents { } } -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, PartialOrd, Eq, Ord)] pub struct Cidr { pub id: i64, @@ -207,6 +207,7 @@ impl Deref for Cidr { } } +#[derive(PartialEq, PartialOrd, Eq, Ord)] pub struct CidrTree<'a> { cidrs: &'a [Cidr], contents: &'a Cidr,