meta: cargo clippy

pull/121/head
Jake McGinty 2021-06-16 20:34:53 +09:00
parent d8513d3d54
commit 7bc1033b58
7 changed files with 18 additions and 20 deletions

View File

@ -657,8 +657,7 @@ fn add_peer(interface: &InterfaceName, opts: AddPeerOpts) -> Result<(), Error> {
let peer: Peer = api.http_form("POST", "/admin/peers", peer_request)?; let peer: Peer = api.http_form("POST", "/admin/peers", peer_request)?;
let server_peer = peers.iter().find(|p| p.id == 1).unwrap(); let server_peer = peers.iter().find(|p| p.id == 1).unwrap();
prompts::write_peer_invitation( prompts::write_peer_invitation(
&mut target_file, (&mut target_file, &target_path),
&target_path,
interface, interface,
&peer, &peer,
server_peer, server_peer,
@ -688,7 +687,7 @@ fn rename_peer(interface: &InterfaceName, opts: RenamePeerOpts) -> Result<(), Er
.filter(|p| p.name == old_name) .filter(|p| p.name == old_name)
.map(|p| p.id) .map(|p| p.id)
.next() .next()
.ok_or(anyhow!("Peer not found."))?; .ok_or_else(|| anyhow!("Peer not found."))?;
let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?; let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
log::info!("Peer renamed."); log::info!("Peer renamed.");
@ -728,11 +727,11 @@ fn add_association(interface: &InterfaceName, opts: AddAssociationOpts) -> Resul
let cidr1 = cidrs let cidr1 = cidrs
.iter() .iter()
.find(|c| &c.name == cidr1) .find(|c| &c.name == cidr1)
.ok_or(anyhow!("can't find cidr '{}'", cidr1))?; .ok_or_else(|| anyhow!("can't find cidr '{}'", cidr1))?;
let cidr2 = cidrs let cidr2 = cidrs
.iter() .iter()
.find(|c| &c.name == cidr2) .find(|c| &c.name == cidr2)
.ok_or(anyhow!("can't find cidr '{}'", cidr2))?; .ok_or_else(|| anyhow!("can't find cidr '{}'", cidr2))?;
(cidr1, cidr2) (cidr1, cidr2)
} else if let Some((cidr1, cidr2)) = prompts::add_association(&cidrs[..])? { } else if let Some((cidr1, cidr2)) = prompts::add_association(&cidrs[..])? {
(cidr1, cidr2) (cidr1, cidr2)
@ -889,7 +888,7 @@ fn show(
let me = peers let me = peers
.iter() .iter()
.find(|p| p.public_key == device_info.public_key.as_ref().unwrap().to_base64()) .find(|p| p.public_key == device_info.public_key.as_ref().unwrap().to_base64())
.ok_or(anyhow!("missing peer info"))?; .ok_or_else(|| anyhow!("missing peer info"))?;
let mut peer_states = device_info let mut peer_states = device_info
.peers .peers

View File

@ -3,7 +3,7 @@ use colored::*;
use indoc::eprintdoc; use indoc::eprintdoc;
use log::{Level, LevelFilter}; use log::{Level, LevelFilter};
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use shared::{interface_config::ServerInfo, WrappedIoError, INNERNET_PUBKEY_HEADER}; use shared::{interface_config::ServerInfo, INNERNET_PUBKEY_HEADER};
use std::{io, time::Duration}; use std::{io, time::Duration};
use ureq::{Agent, AgentBuilder}; use ureq::{Agent, AgentBuilder};

View File

@ -140,7 +140,8 @@ pub fn init_wizard(conf: &ServerConfig, opts: InitializeOpts) -> Result<(), Erro
let endpoint: Endpoint = if let Some(endpoint) = opts.external_endpoint { let endpoint: Endpoint = if let Some(endpoint) = opts.external_endpoint {
endpoint endpoint
} else if opts.auto_external_endpoint { } else if opts.auto_external_endpoint {
let ip = publicip::get_any(Preference::Ipv4).ok_or(anyhow!("couldn't get external IP"))?; let ip = publicip::get_any(Preference::Ipv4)
.ok_or_else(|| anyhow!("couldn't get external IP"))?;
SocketAddr::new(ip, 51820).into() SocketAddr::new(ip, 51820).into()
} else { } else {
prompts::ask_endpoint()? prompts::ask_endpoint()?

View File

@ -308,8 +308,7 @@ fn add_peer(
let server_peer = DatabasePeer::get(&conn, 1)?; let server_peer = DatabasePeer::get(&conn, 1)?;
prompts::write_peer_invitation( prompts::write_peer_invitation(
&mut target_file, (&mut target_file, &target_path),
&target_path,
interface, interface,
&peer, &peer,
&*server_peer, &*server_peer,
@ -339,7 +338,7 @@ fn rename_peer(
let mut db_peer = DatabasePeer::list(&conn)? let mut db_peer = DatabasePeer::list(&conn)?
.into_iter() .into_iter()
.find(|p| p.name == old_name) .find(|p| p.name == old_name)
.ok_or(anyhow!("Peer not found."))?; .ok_or_else(|| anyhow!("Peer not found."))?;
let _peer = db_peer.update(&conn, peer_request)?; let _peer = db_peer.update(&conn, peer_request)?;
} else { } else {
println!("exited without creating peer."); println!("exited without creating peer.");

View File

@ -80,7 +80,7 @@ pub fn add_cidr(cidrs: &[Cidr], request: &AddCidrOpts) -> Result<Option<CidrCont
cidrs cidrs
.iter() .iter()
.find(|cidr| &cidr.name == parent_name) .find(|cidr| &cidr.name == parent_name)
.ok_or(anyhow!("No parent CIDR with that name exists."))? .ok_or_else(|| anyhow!("No parent CIDR with that name exists."))?
} else { } else {
choose_cidr(cidrs, "Parent CIDR")? choose_cidr(cidrs, "Parent CIDR")?
}; };
@ -219,7 +219,7 @@ pub fn add_peer(
leaves leaves
.iter() .iter()
.find(|cidr| &cidr.name == parent_name) .find(|cidr| &cidr.name == parent_name)
.ok_or(anyhow!("No eligible CIDR with that name exists."))? .ok_or_else(|| anyhow!("No eligible CIDR with that name exists."))?
} else { } else {
choose_cidr(&leaves[..], "Eligible CIDRs for peer")? choose_cidr(&leaves[..], "Eligible CIDRs for peer")?
}; };
@ -384,8 +384,7 @@ pub fn enable_or_disable_peer(peers: &[Peer], enable: bool) -> Result<Option<Pee
/// Confirm and write a innernet invitation file after a peer has been created. /// Confirm and write a innernet invitation file after a peer has been created.
pub fn write_peer_invitation( pub fn write_peer_invitation(
target_file: &mut File, target_file: (&mut File, &str),
target_path: &str,
network_name: &InterfaceName, network_name: &InterfaceName,
peer: &Peer, peer: &Peer,
server_peer: &Peer, server_peer: &Peer,
@ -410,7 +409,7 @@ pub fn write_peer_invitation(
}, },
}; };
peer_invitation.write_to(target_file, true, None)?; peer_invitation.write_to(target_file.0, true, None)?;
println!( println!(
"\nPeer \"{}\" added\n\ "\nPeer \"{}\" added\n\
@ -418,7 +417,7 @@ pub fn write_peer_invitation(
Please send it to them securely (eg. via magic-wormhole) \ Please send it to them securely (eg. via magic-wormhole) \
to bootstrap them onto the network.", to bootstrap them onto the network.",
peer.name.bold(), peer.name.bold(),
target_path.bold() target_file.1.bold()
); );
Ok(()) Ok(())

View File

@ -249,7 +249,7 @@ pub fn get_by_name(name: &InterfaceName) -> Result<Device, io::Error> {
match reader.read_line(&mut buf)? { match reader.read_line(&mut buf)? {
0 | 1 if buf == "\n" => break, 0 | 1 if buf == "\n" => break,
_ => { _ => {
parser.add_line(&buf.trim_end())?; parser.add_line(buf.trim_end())?;
buf.clear(); buf.clear();
}, },
}; };

View File

@ -420,8 +420,8 @@ impl DeviceUpdate {
pub fn apply(self, iface: &InterfaceName, backend: Backend) -> io::Result<()> { pub fn apply(self, iface: &InterfaceName, backend: Backend) -> io::Result<()> {
match backend { match backend {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
Backend::Kernel => backends::kernel::apply(&self, &iface), Backend::Kernel => backends::kernel::apply(&self, iface),
Backend::Userspace => backends::userspace::apply(&self, &iface), Backend::Userspace => backends::userspace::apply(&self, iface),
} }
} }
} }