diff options
author | Aram Drevekenin <aram@poor.dev> | 2019-11-18 17:38:45 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2019-11-18 17:38:45 +0100 |
commit | a0a3cd5c7c81a92eb297bd13ac32972a9b79df56 (patch) | |
tree | a3d682e78da77f2e8ebd8328bcd42e56bc8af2a8 | |
parent | a645740135d7adab4b33e94f3ef8f2065b4ae834 (diff) |
refactor(style): rustfmt
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/network/utilization.rs | 4 | ||||
-rw-r--r-- | src/os/lsof_utils.rs | 36 | ||||
-rw-r--r-- | src/os/macos.rs | 4 |
4 files changed, 28 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 0df169b..7626615 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,9 +50,7 @@ fn main() { fn try_main() -> Result<(), failure::Error> { #[cfg(target_os = "windows")] - compile_error!( - "Sorry, no implementations for Windows yet :( - PRs welcome!" - ); + compile_error!("Sorry, no implementations for Windows yet :( - PRs welcome!"); use os::get_input; let opts = Opt::from_args(); diff --git a/src/network/utilization.rs b/src/network/utilization.rs index 54870dd..cb0f12b 100644 --- a/src/network/utilization.rs +++ b/src/network/utilization.rs @@ -16,9 +16,7 @@ pub struct Utilization { impl Utilization { pub fn new() -> Self { let connections = HashMap::new(); - Utilization { - connections, - } + Utilization { connections } } pub fn clone_and_reset(&mut self) -> Self { let clone = self.clone(); diff --git a/src/os/lsof_utils.rs b/src/os/lsof_utils.rs index caabd26..9f6b479 100644 --- a/src/os/lsof_utils.rs +++ b/src/os/lsof_utils.rs @@ -1,9 +1,9 @@ -use std::process::{Command}; -use std::ffi::OsStr; -use regex::{Regex}; use crate::network::Protocol; -use std::net::IpAddr; use lazy_static::lazy_static; +use regex::Regex; +use std::ffi::OsStr; +use std::net::IpAddr; +use std::process::Command; #[derive(Debug, Clone)] pub struct RawConnection { @@ -15,7 +15,8 @@ pub struct RawConnection { } lazy_static! { - static ref CONNECTION_REGEX: Regex = Regex::new(r"([^\s]+).*(TCP|UDP).*:(.*)->(.*):(\d*)(\s|$)").unwrap(); + static ref CONNECTION_REGEX: Regex = + Regex::new(r"([^\s]+).*(TCP|UDP).*:(.*)->(.*):(\d*)(\s|$)").unwrap(); } impl RawConnection { @@ -26,7 +27,13 @@ impl RawConnection { let local_port = String::from(cap.get(3).unwrap().as_str()); let ip = String::from(cap.get(4).unwrap().as_str()); let remote_port = String::from(cap.get(5).unwrap().as_str()); - let connection = RawConnection { process_name, ip, local_port, remote_port, protocol }; + let connection = RawConnection { + process_name, + ip, + local_port, + remote_port, + protocol, + }; Some(connection) }); let raw_connection_vec = raw_connection_iter.map(|m| m).collect::<Vec<_>>(); @@ -55,12 +62,14 @@ impl RawConnection { } pub fn get_connections<'a>() -> RawConnections { - let content = run(&["-n","-P", "-i4"]); + let content = run(&["-n", "-P", "-i4"]); RawConnections::new(content) } fn run<'a, I, S>(args: I) -> String - where I: IntoIterator<Item=S>, S: AsRef<OsStr> +where + I: IntoIterator<Item = S>, + S: AsRef<OsStr>, { let output = Command::new("lsof") .args(args) @@ -76,11 +85,12 @@ pub struct RawConnections { impl RawConnections { pub fn new(content: String) -> RawConnections { - let lines: Vec<RawConnection> = content.lines() + let lines: Vec<RawConnection> = content + .lines() .flat_map(|string| RawConnection::new(string)) .collect(); - RawConnections{ content: lines } + RawConnections { content: lines } } } @@ -92,7 +102,6 @@ impl Iterator for RawConnections { } } - #[cfg(test)] mod tests { use super::*; @@ -150,7 +159,10 @@ com.apple 590 etoledom 204u IPv4 0x28ffb9c04111253f 0t0 TCP 192.168.1. #[test] fn test_raw_connection_parse_ip_address() { let connection = RawConnection::new(LINE_RAW_OUTPUT).unwrap(); - assert_eq!(connection.get_ip_address().to_string(), String::from("198.252.206.25")); + assert_eq!( + connection.get_ip_address().to_string(), + String::from("198.252.206.25") + ); } #[test] diff --git a/src/os/macos.rs b/src/os/macos.rs index 2bba346..47248d0 100644 --- a/src/os/macos.rs +++ b/src/os/macos.rs @@ -10,11 +10,11 @@ use ::std::net::IpAddr; use signal_hook::iterator::Signals; -use crate::network::{Connection}; +use crate::network::Connection; use crate::OsInputOutput; -use std::net::{SocketAddr}; use super::lsof_utils; +use std::net::SocketAddr; struct KeyboardEvents; |