From 65f87d678fdb05b79974a5d156e8abce3f9678df Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Sun, 29 Jul 2018 20:07:31 +0200 Subject: [PATCH] ty clippy --- src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index bf34874..e09f338 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,16 +96,16 @@ fn get_inodes(inodes: &mut HashMap) { }; let target_str = target.to_str().unwrap(); - let pid = path_str.split("/").nth(2).unwrap().parse(); - if !pid.is_ok() { + let pid = path_str.split('/').nth(2).unwrap().parse(); + if pid.is_err() { continue; } if target_str.starts_with("socket") { - let inode_str = target_str.splitn(2, ":").nth(1).unwrap(); + let inode_str = target_str.splitn(2, ':').nth(1).unwrap(); let inode = inode_str[1..(inode_str.len() - 1)].parse().unwrap(); - let mut inode = inodes.entry(inode).or_insert(INode::new()); + let mut inode = inodes.entry(inode).or_insert_with(INode::new); let process = Process { pid: pid.unwrap(), command_line: None }; inode.processes.push(process); } @@ -115,7 +115,7 @@ fn get_inodes(inodes: &mut HashMap) { fn get_command_lines(inodes: &mut HashMap) { for inode in inodes.values_mut() { - for process in inode.processes.iter_mut() { + for process in &mut inode.processes { let filename = format!("/proc/{}/cmdline", process.pid); let file = File::open(filename).unwrap(); let mut buffer = BufReader::new(file); @@ -130,15 +130,15 @@ fn get_command_lines(inodes: &mut HashMap) { fn get_addresses(inodes: &mut HashMap) { - for protocol in [Protocol::Tcp, Protocol::Udp].iter() { - for version in ["", "6"].iter() { + for protocol in &[Protocol::Tcp, Protocol::Udp] { + for version in &["", "6"] { let filename = format!("/proc/net/{}{}", protocol, version); let file = File::open(filename).unwrap(); let buffer = BufReader::new(file); let connections = buffer.lines().skip(1).map(|line| line.unwrap()); for connection in connections { - let fields: Vec<&str> = connection.split_whitespace().collect(); + let fields: Vec<_> = connection.split_whitespace().collect(); let state = fields[3]; if state != "0A" && state != "07" { @@ -146,8 +146,8 @@ fn get_addresses(inodes: &mut HashMap) { continue; } - let address: Vec<&str> = fields[1].split(":").collect(); - let ip = match version { &"6" => parse_ipv6, _ => parse_ipv4 }(address[0]); + let address: Vec<_> = fields[1].split(':').collect(); + let ip = match *version { "6" => parse_ipv6, _ => parse_ipv4 }(address[0]); let port = u16::from_str_radix(address[1], 16).unwrap(); let inode_id = fields[9].parse().unwrap(); @@ -168,13 +168,13 @@ fn print_all(inodes: &HashMap) { None => 80, }; - let mut values: Vec<&INode> = inodes.values().collect(); + let mut values: Vec<_> = inodes.values().collect(); values.sort_unstable_by(|a, b| a.processes[0].pid.cmp(&b.processes[0].pid)); for inode in values { for address in &inode.addresses { for (i, process) in inode.processes.iter().enumerate() { - let command_line = process.command_line.clone().unwrap_or("".to_owned()); + let command_line = process.command_line.clone().unwrap_or_default(); let address_str = if i == 0 { format!("{}", address) } else { String::new() }; let mut output = format!(