Fix clippy warnings

Especially https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string was a bit
more involved, review requested.
pull/230/head^2
Matěj Laitl 2022-07-29 10:12:43 +02:00
parent 986a47fab3
commit 144c2f654e
4 changed files with 31 additions and 26 deletions

View File

@ -725,7 +725,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &sub_opts)?;
println!("Deleting CIDR...");
let _ = api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?;
api.http("DELETE", &*format!("/admin/cidrs/{}", cidr_id))?;
println!("CIDR deleted.");
@ -801,7 +801,7 @@ fn rename_peer(
.next()
.ok_or_else(|| anyhow!("Peer not found."))?;
let _ = api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
api.http_form("PUT", &format!("/admin/peers/{}", id), peer_request)?;
log::info!("Peer renamed.");
} else {
log::info!("exited without renaming peer.");

View File

@ -357,7 +357,7 @@ fn rename_peer(
.into_iter()
.find(|p| p.name == old_name)
.ok_or_else(|| anyhow!("Peer not found."))?;
let _peer = db_peer.update(&conn, peer_request)?;
db_peer.update(&conn, peer_request)?;
} else {
println!("exited without creating peer.");
}
@ -408,7 +408,7 @@ fn delete_cidr(
let cidr_id = prompts::delete_cidr(&cidrs, &peers, &args)?;
println!("Deleting CIDR...");
let _ = DatabaseCidr::delete(&conn, cidr_id)?;
DatabaseCidr::delete(&conn, cidr_id)?;
println!("CIDR deleted.");

View File

@ -34,7 +34,7 @@ macro_rules! get_nla_value {
};
}
impl<'a> TryFrom<WgAllowedIp> for AllowedIp {
impl TryFrom<WgAllowedIp> for AllowedIp {
type Error = io::Error;
fn try_from(attrs: WgAllowedIp) -> Result<Self, Self::Error> {
@ -88,7 +88,7 @@ impl PeerConfigBuilder {
}
}
impl<'a> TryFrom<WgPeer> for PeerInfo {
impl TryFrom<WgPeer> for PeerInfo {
type Error = io::Error;
fn try_from(attrs: WgPeer) -> Result<Self, Self::Error> {

View File

@ -1,8 +1,7 @@
use crate::{Backend, Device, DeviceUpdate, InterfaceName, PeerConfig, PeerInfo, PeerStats};
use crate::Key;
use crate::{Backend, Device, DeviceUpdate, InterfaceName, Key, PeerConfig, PeerInfo, PeerStats};
use std::{
fmt::Write as _,
fs,
io::{self, prelude::*, BufReader},
os::unix::net::UnixStream,
@ -311,55 +310,61 @@ pub fn apply(builder: &DeviceUpdate, iface: &InterfaceName) -> io::Result<()> {
let mut request = String::from("set=1\n");
if let Some(ref k) = builder.private_key {
request.push_str(&format!("private_key={}\n", hex::encode(k.as_bytes())));
writeln!(request, "private_key={}", hex::encode(k.as_bytes())).ok();
}
if let Some(f) = builder.fwmark {
request.push_str(&format!("fwmark={}\n", f));
writeln!(request, "fwmark={}", f).ok();
}
if let Some(f) = builder.listen_port {
request.push_str(&format!("listen_port={}\n", f));
writeln!(request, "listen_port={}", f).ok();
}
if builder.replace_peers {
request.push_str("replace_peers=true\n");
writeln!(request, "replace_peers=true").ok();
}
for peer in &builder.peers {
request.push_str(&format!(
"public_key={}\n",
writeln!(
request,
"public_key={}",
hex::encode(peer.public_key.as_bytes())
));
)
.ok();
if peer.replace_allowed_ips {
request.push_str("replace_allowed_ips=true\n");
writeln!(request, "replace_allowed_ips=true").ok();
}
if peer.remove_me {
request.push_str("remove=true\n");
writeln!(request, "remove=true").ok();
}
if let Some(ref k) = peer.preshared_key {
request.push_str(&format!("preshared_key={}\n", hex::encode(k.as_bytes())));
writeln!(request, "preshared_key={}", hex::encode(k.as_bytes())).ok();
}
if let Some(endpoint) = peer.endpoint {
request.push_str(&format!("endpoint={}\n", endpoint));
writeln!(request, "endpoint={}", endpoint).ok();
}
if let Some(keepalive_interval) = peer.persistent_keepalive_interval {
request.push_str(&format!(
"persistent_keepalive_interval={}\n",
writeln!(
request,
"persistent_keepalive_interval={}",
keepalive_interval
));
)
.ok();
}
for allowed_ip in &peer.allowed_ips {
request.push_str(&format!(
"allowed_ip={}/{}\n",
writeln!(
request,
"allowed_ip={}/{}",
allowed_ip.address, allowed_ip.cidr
));
)
.ok();
}
}