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(
interface: &InterfaceName,
hosts_path: PathBuf,
peers: &Vec<Peer>,
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<Interface>) -> 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<Interface>) -> 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));

View File

@ -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<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());
}
@ -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());
}
}

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 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,