From 51c9e1433bf139759a41173aa63fa40855a10fac Mon Sep 17 00:00:00 2001 From: Hristo Venev Date: Tue, 19 Mar 2019 17:46:48 +0200 Subject: lint --- src/builder.rs | 32 +++++++++++++++++--------------- src/config.rs | 2 +- src/main.rs | 5 +---- src/model.rs | 16 ++++++++++------ src/proto.rs | 6 ++++-- src/wg.rs | 4 ++-- 6 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index cc42fa8..ba3843b 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -3,9 +3,8 @@ // See COPYING. use crate::{config, model, proto}; -use std::{error, fmt}; use std::collections::hash_map; - +use std::{error, fmt}; #[derive(Debug)] pub struct ConfigError { @@ -68,11 +67,7 @@ impl<'a> ConfigBuilder<'a> { } #[inline] - pub fn add_server( - &mut self, - s: &config::Source, - p: &proto::Server, - ) { + pub fn add_server(&mut self, s: &config::Source, p: &proto::Server) { if p.peer.public_key == self.public_key { return; } @@ -88,13 +83,14 @@ impl<'a> ConfigBuilder<'a> { } #[inline] - pub fn add_road_warrior( - &mut self, - s: &config::Source, - p: &proto::RoadWarrior, - ) { + pub fn add_road_warrior(&mut self, s: &config::Source, p: &proto::RoadWarrior) { if p.peer.public_key == self.public_key { - self.err.push(ConfigError::new("The local peer cannot be a road warrior", s, &p.peer, true)); + self.err.push(ConfigError::new( + "The local peer cannot be a road warrior", + s, + &p.peer, + true, + )); return; } @@ -104,7 +100,8 @@ impl<'a> ConfigBuilder<'a> { match self.c.peers.get_mut(&p.base) { Some(ent) => ent, None => { - self.err.push(ConfigError::new("Unknown base peer", s, &p.peer, true)); + self.err + .push(ConfigError::new("Unknown base peer", s, &p.peer, true)); return; } } @@ -140,7 +137,12 @@ fn insert_peer<'b>( } } -fn add_peer(err: &mut Vec, ent: &mut model::Peer, s: &config::Source, p: &proto::Peer) { +fn add_peer( + err: &mut Vec, + ent: &mut model::Peer, + s: &config::Source, + p: &proto::Peer, +) { let mut added = false; let mut removed = false; diff --git a/src/config.rs b/src/config.rs index 98db02d..e8dcb05 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,7 @@ // See COPYING. use crate::ip::{Ipv4Set, Ipv6Set}; -use crate::model::{Key}; +use crate::model::Key; use serde_derive; #[serde(deny_unknown_fields)] diff --git a/src/main.rs b/src/main.rs index 18ce199..15ca6d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -198,10 +198,7 @@ fn fetch_source(url: &str) -> io::Result { if !out.status.success() { let msg = String::from_utf8_lossy(&out.stderr); let msg = msg.replace('\n', "; "); - return Err(io::Error::new( - io::ErrorKind::Other, - msg, - )); + return Err(io::Error::new(io::ErrorKind::Other, msg)); } let mut de = serde_json::Deserializer::from_slice(&out.stdout); diff --git a/src/model.rs b/src/model.rs index a7675f2..f8b76b5 100644 --- a/src/model.rs +++ b/src/model.rs @@ -2,11 +2,11 @@ // // See COPYING. -use base64; use crate::bin; -use crate::ip::{Ipv4Addr, Ipv6Addr, Ipv4Net, Ipv6Net, NetParseError}; -use std::{fmt}; -use std::collections::{HashMap}; +use crate::ip::{Ipv4Addr, Ipv4Net, Ipv6Addr, Ipv6Net, NetParseError}; +use base64; +use std::collections::HashMap; +use std::fmt; use std::str::FromStr; pub type KeyParseError = base64::DecodeError; @@ -28,7 +28,11 @@ impl Key { impl fmt::Display for Key { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", base64::display::Base64Display::with_config(&self.0, base64::STANDARD)) + write!( + f, + "{}", + base64::display::Base64Display::with_config(&self.0, base64::STANDARD) + ) } } @@ -90,7 +94,7 @@ impl Endpoint { pub fn ipv4_address(&self) -> Option { let seg = self.address.octets(); let (first, second) = array_refs![&seg, 12, 4]; - if *first == [0,0,0,0,0,0,0,0,0,0,0xff,0xff] { + if *first == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff] { Some(Ipv4Addr::from(*second)) } else { None diff --git a/src/proto.rs b/src/proto.rs index bfc3cbb..86c7eee 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -3,7 +3,7 @@ // See COPYING. use crate::ip::{Ipv4Net, Ipv6Net}; -use crate::model::{Key, Endpoint}; +use crate::model::{Endpoint, Key}; use serde_derive; use std::time::SystemTime; @@ -94,7 +94,9 @@ mod serde_utc { } fn visit_str(self, s: &str) -> Result { - DateTime::parse_from_rfc3339(s).map_err(de::Error::custom).map(SystemTime::from) + DateTime::parse_from_rfc3339(s) + .map_err(de::Error::custom) + .map(SystemTime::from) } } de.deserialize_str(RFC3339Visitor) diff --git a/src/wg.rs b/src/wg.rs index 0335c3d..b3ec451 100644 --- a/src/wg.rs +++ b/src/wg.rs @@ -2,10 +2,10 @@ // // See COPYING. -use crate::{model}; -use std::{env, io}; +use crate::model; use std::ffi::{OsStr, OsString}; use std::process::{Command, Stdio}; +use std::{env, io}; pub struct Device { ifname: String, -- cgit