client: make clippy happy

pull/71/head
Jake McGinty 2021-05-06 12:40:00 +09:00
parent c01c2be4bb
commit f27a2426c8
3 changed files with 11 additions and 10 deletions

View File

@ -187,7 +187,7 @@ impl std::error::Error for ClientError {
fn update_hosts_file( fn update_hosts_file(
interface: &InterfaceName, interface: &InterfaceName,
hosts_path: PathBuf, hosts_path: PathBuf,
peers: &Vec<Peer>, peers: &[Peer],
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( println!(
"{} updating {} with the latest peers.", "{} updating {} with the latest peers.",
@ -445,7 +445,7 @@ fn fetch(
for peer in existing_peers { for peer in existing_peers {
let public_key = peer.config.public_key.to_base64(); 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!( println!(
" peer ({}...) was {}.", " peer ({}...) was {}.",
&public_key[..10].yellow(), &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<Interface>) -> Result<(), Error> { fn show(short: bool, tree: bool, interface: Option<Interface>) -> Result<(), Error> {
let interfaces = 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| { let devices = interfaces.into_iter().filter_map(|name| {
DataStore::open(&name) DataStore::open(&name)
@ -744,7 +744,7 @@ fn show(short: bool, tree: bool, interface: Option<Interface>) -> Result<(), Err
}); });
if tree { if tree {
let cidr_tree = CidrTree::new(&cidrs[..]); let cidr_tree = CidrTree::new(cidrs);
print_tree(&cidr_tree, &peers, 1); print_tree(&cidr_tree, &peers, 1);
} else { } else {
for peer in device_info.peers { 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(); let mut children: Vec<_> = cidr.children().collect();
children.sort_by(|a, b| a.cmp(&b)); children.sort();
children children
.iter() .iter()
.for_each(|child| print_tree(&child, peers, level + 1)); .for_each(|child| print_tree(&child, peers, level + 1));

View File

@ -88,7 +88,7 @@ impl HostsBuilder {
/// Adds a mapping of `ip` to `hostname`. If there hostnames associated with the IP already, /// Adds a mapping of `ip` to `hostname`. If there hostnames associated with the IP already,
/// the hostname will be appended to the list. /// the hostname will be appended to the list.
pub fn add_hostname<S: ToString>(&mut self, ip: IpAddr, hostname: S) { pub fn add_hostname<S: ToString>(&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()); hostnames_dest.push(hostname.to_string());
} }
@ -99,7 +99,7 @@ impl HostsBuilder {
ip: IpAddr, ip: IpAddr,
hostnames: I, 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() { for hostname in hostnames.into_iter() {
hostnames_dest.push(hostname.to_string()); hostnames_dest.push(hostname.to_string());
} }
@ -153,7 +153,7 @@ impl HostsBuilder {
(None, None) => { (None, None) => {
// Insert a blank line before a new section. // Insert a blank line before a new section.
if let Some(last_line) = lines.iter().last() { if let Some(last_line) = lines.iter().last() {
if last_line != "" { if !last_line.is_empty() {
lines.push("".to_string()); lines.push("".to_string());
} }
} }

View File

@ -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 struct CidrContents {
pub name: String, pub name: String,
pub cidr: IpNetwork, 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 struct Cidr {
pub id: i64, pub id: i64,
@ -207,6 +207,7 @@ impl Deref for Cidr {
} }
} }
#[derive(PartialEq, PartialOrd, Eq, Ord)]
pub struct CidrTree<'a> { pub struct CidrTree<'a> {
cidrs: &'a [Cidr], cidrs: &'a [Cidr],
contents: &'a Cidr, contents: &'a Cidr,