summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2019-10-06 17:21:33 +0200
committerAram Drevekenin <aram@poor.dev>2019-10-06 17:21:33 +0200
commit55c830d6bb15af66534ba81fdb9a130b63144d4a (patch)
tree5d7c469c79fc5ebea2a461e03d82d41e22e25c6e
parent9a212ae864a48089e429fd7375c817291a4b9c7d (diff)
fix(styling): clippy
-rw-r--r--src/display/ui.rs22
-rw-r--r--src/main.rs2
-rw-r--r--src/network/dns_queue.rs4
-rw-r--r--src/network/sniffer.rs9
-rw-r--r--src/tests/fakes/fake_input.rs5
5 files changed, 21 insertions, 21 deletions
diff --git a/src/display/ui.rs b/src/display/ui.rs
index dae50aa..a3f9b58 100644
--- a/src/display/ui.rs
+++ b/src/display/ui.rs
@@ -16,10 +16,10 @@ struct DisplayBandwidth(f64);
impl fmt::Display for DisplayBandwidth {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if self.0 > 999999999.0 {
- write!(f, "{:.2}GBps", self.0 / 1000000000.0)
- } else if self.0 > 999999.0 {
- write!(f, "{:.2}MBps", self.0 / 1000000.0)
+ if self.0 > 999_999_999.0 {
+ write!(f, "{:.2}GBps", self.0 / 1_000_000_000.0)
+ } else if self.0 > 999_999.0 {
+ write!(f, "{:.2}MBps", self.0 / 1_000_000.0)
} else if self.0 > 999.0 {
write!(f, "{:.2}KBps", self.0 / 1000.0)
} else {
@@ -28,8 +28,8 @@ impl fmt::Display for DisplayBandwidth {
}
}
-fn display_ip_or_host(ip: &Ipv4Addr, ip_to_host: &HashMap<Ipv4Addr, String>) -> String {
- match ip_to_host.get(ip) {
+fn display_ip_or_host(ip: Ipv4Addr, ip_to_host: &HashMap<Ipv4Addr, String>) -> String {
+ match ip_to_host.get(&ip) {
Some(host) => host.clone(),
None => ip.to_string(),
}
@@ -43,7 +43,7 @@ fn create_table<'a>(
) -> impl Widget + 'a {
let table_rows =
rows.map(|row| Row::StyledData(row.into_iter(), Style::default().fg(Color::White)));
- Table::new(column_names.into_iter(), table_rows)
+ Table::new(column_names.iter(), table_rows)
.block(Block::default().title(title).borders(Borders::ALL))
.header_style(Style::default().fg(Color::Yellow))
.widths(widths)
@@ -107,9 +107,9 @@ fn render_connections_table(
.map(|(connection, connection_data)| {
let connection_string = format!(
"{}:{} => {}:{} ({})",
- display_ip_or_host(&connection.local_socket.ip, ip_to_host),
+ display_ip_or_host(connection.local_socket.ip, ip_to_host),
connection.local_socket.port,
- display_ip_or_host(&connection.remote_socket.ip, ip_to_host),
+ display_ip_or_host(connection.remote_socket.ip, ip_to_host),
connection.remote_socket.port,
connection.protocol,
);
@@ -138,7 +138,7 @@ fn render_remote_ip_table(
.remote_ips
.iter()
.map(|(remote_ip, data_for_remote_ip)| {
- let remote_ip = display_ip_or_host(remote_ip, &ip_to_host);
+ let remote_ip = display_ip_or_host(*remote_ip, &ip_to_host);
format_row_data(
remote_ip,
data_for_remote_ip.connection_count.to_string(),
@@ -172,7 +172,7 @@ where
terminal.clear().unwrap();
terminal.hide_cursor().unwrap();
Ui {
- terminal: terminal,
+ terminal,
state: Default::default(),
ip_to_host: Default::default(),
}
diff --git a/src/main.rs b/src/main.rs
index eb92eef..60a7c4d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -95,7 +95,7 @@ where
let ip_to_host = ip_to_host.clone();
move || {
while let Some(ip) = dns_queue.wait_for_job() {
- if let Some(addr) = lookup_addr(&IpAddr::V4(ip.clone())) {
+ if let Some(addr) = lookup_addr(&IpAddr::V4(ip)) {
ip_to_host.lock().unwrap().insert(ip, addr);
}
}
diff --git a/src/network/dns_queue.rs b/src/network/dns_queue.rs
index f5c1ddf..ddb2d9a 100644
--- a/src/network/dns_queue.rs
+++ b/src/network/dns_queue.rs
@@ -27,10 +27,10 @@ impl DnsQueue {
let mut queue = self.jobs.lock().unwrap();
for connection in connections_to_procs.keys() {
if !ip_to_host.contains_key(&connection.local_socket.ip) {
- queue.push(Some(connection.local_socket.ip.clone()));
+ queue.push(Some(connection.local_socket.ip));
}
if !ip_to_host.contains_key(&connection.remote_socket.ip) {
- queue.push(Some(connection.remote_socket.ip.clone()));
+ queue.push(Some(connection.remote_socket.ip));
}
}
self.cvar.notify_all();
diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs
index 93f55a4..4c1c3e2 100644
--- a/src/network/sniffer.rs
+++ b/src/network/sniffer.rs
@@ -26,13 +26,14 @@ pub enum Direction {
}
impl Direction {
- pub fn new(network_interface_ips: &Vec<IpNetwork>, ip_packet: &Ipv4Packet) -> Self {
- match network_interface_ips
+ pub fn new(network_interface_ips: &[IpNetwork], ip_packet: &Ipv4Packet) -> Self {
+ if network_interface_ips
.iter()
.any(|ip_network| ip_network.ip() == ip_packet.get_source())
{
- true => Direction::Upload,
- false => Direction::Download,
+ Direction::Upload
+ } else {
+ Direction::Download
}
}
}
diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs
index ac02c36..ea1f34c 100644
--- a/src/tests/fakes/fake_input.rs
+++ b/src/tests/fakes/fake_input.rs
@@ -136,14 +136,13 @@ pub fn get_open_sockets() -> HashMap<Connection, String> {
}
pub fn get_interface() -> NetworkInterface {
- let interface = NetworkInterface {
+ NetworkInterface {
name: String::from("foo"),
index: 42,
mac: None,
ips: vec![IpNetwork::V4("10.0.0.2".parse().unwrap())],
flags: 42,
- };
- interface
+ }
}
pub fn create_fake_lookup_addr(