diff options
author | Quang Luong <quangio@outlook.com> | 2020-09-18 11:20:06 +0700 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2020-10-08 10:19:51 +0200 |
commit | 9b53a9d1a61115a328ca43955153d09cc2e969ef (patch) | |
tree | b84d83a431dfdc5777e61d40c60c7b0de088f8fd /src/configuration | |
parent | Added MIT license (diff) | |
download | wireguard-rs-9b53a9d1a61115a328ca43955153d09cc2e969ef.tar.xz wireguard-rs-9b53a9d1a61115a328ca43955153d09cc2e969ef.zip |
Fix some clippy warnings
Signed-off-by: Quang Luong <quangio@outlook.com>
Diffstat (limited to 'src/configuration')
-rw-r--r-- | src/configuration/config.rs | 6 | ||||
-rw-r--r-- | src/configuration/uapi/get.rs | 9 | ||||
-rw-r--r-- | src/configuration/uapi/mod.rs | 9 | ||||
-rw-r--r-- | src/configuration/uapi/set.rs | 2 |
4 files changed, 12 insertions, 14 deletions
diff --git a/src/configuration/config.rs b/src/configuration/config.rs index 536d612..636becc 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -358,11 +358,11 @@ impl<T: tun::Tun, B: udp::PlatformUDP> Configuration for WireGuardConfig<T, B> { for (pk, p) in peers.iter() { // convert the system time to (secs, nano) since epoch - let last_handshake_time = (*p.walltime_last_handshake.lock()).and_then(|t| { + let last_handshake_time = (*p.walltime_last_handshake.lock()).map(|t| { let duration = t .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or(Duration::from_secs(0)); - Some((duration.as_secs(), duration.subsec_nanos() as u64)) + .unwrap_or_else(|_| Duration::from_secs(0)); + (duration.as_secs(), duration.subsec_nanos() as u64) }); if let Some(psk) = cfg.wireguard.get_psk(&pk) { diff --git a/src/configuration/uapi/get.rs b/src/configuration/uapi/get.rs index 00048cd..8ca9d64 100644 --- a/src/configuration/uapi/get.rs +++ b/src/configuration/uapi/get.rs @@ -1,4 +1,3 @@ -use log; use std::io; use super::Configuration; @@ -8,10 +7,10 @@ pub fn serialize<C: Configuration, W: io::Write>(writer: &mut W, config: &C) -> debug_assert!(value.is_ascii()); debug_assert!(key.is_ascii()); log::trace!("UAPI: return : {}={}", key, value); - writer.write(key.as_ref())?; - writer.write(b"=")?; - writer.write(value.as_ref())?; - writer.write(b"\n") + writer.write_all(key.as_ref())?; + writer.write_all(b"=")?; + writer.write_all(value.as_ref())?; + writer.write_all(b"\n") }; // serialize interface diff --git a/src/configuration/uapi/mod.rs b/src/configuration/uapi/mod.rs index 9f54775..63a8d5f 100644 --- a/src/configuration/uapi/mod.rs +++ b/src/configuration/uapi/mod.rs @@ -1,7 +1,6 @@ mod get; mod set; -use log; use std::io::{Read, Write}; use super::{ConfigError, Configuration}; @@ -20,7 +19,7 @@ pub fn handle<S: Read + Write, C: Configuration>(stream: &mut S, config: &C) { fn readline<R: Read>(reader: &mut R) -> Result<String, ConfigError> { let mut m: [u8; 1] = [0u8]; let mut l: String = String::with_capacity(MAX_LINE_LENGTH); - while let Ok(_) = reader.read_exact(&mut m) { + while reader.read_exact(&mut m).is_ok() { let c = m[0] as char; if c == '\n' { log::trace!("UAPI, line: {}", l); @@ -31,12 +30,12 @@ pub fn handle<S: Read + Write, C: Configuration>(stream: &mut S, config: &C) { return Err(ConfigError::LineTooLong); } } - return Err(ConfigError::IOError); + Err(ConfigError::IOError) } // split into (key, value) pair - fn keypair<'a>(ln: &'a str) -> Result<(&'a str, &'a str), ConfigError> { - let mut split = ln.splitn(2, "="); + fn keypair(ln: &str) -> Result<(&str, &str), ConfigError> { + let mut split = ln.splitn(2, '='); match (split.next(), split.next()) { (Some(key), Some(value)) => Ok((key, value)), _ => Err(ConfigError::LineTooLong), diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index ca0b59a..665f090 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -220,7 +220,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { // opt add allowed ips "allowed_ip" => { - let mut split = value.splitn(2, "/"); + let mut split = value.splitn(2, '/'); let addr = split.next().and_then(|x| x.parse().ok()); let cidr = split.next().and_then(|x| x.parse().ok()); match (addr, cidr) { |