From ec0ca81a051c5dd91e448ef435e5e74c127cde91 Mon Sep 17 00:00:00 2001 From: Badr Date: Sun, 19 Jan 2025 21:31:28 +0100 Subject: [PATCH] remove useless .collect --- oryx-tui/src/ebpf/firewall.rs | 14 ++++---- oryx-tui/src/help.rs | 11 ++---- oryx-tui/src/interface.rs | 62 +++++++++++++++------------------ oryx-tui/src/section/metrics.rs | 4 +-- 4 files changed, 39 insertions(+), 52 deletions(-) diff --git a/oryx-tui/src/ebpf/firewall.rs b/oryx-tui/src/ebpf/firewall.rs index 0156f09..864588d 100644 --- a/oryx-tui/src/ebpf/firewall.rs +++ b/oryx-tui/src/ebpf/firewall.rs @@ -30,13 +30,12 @@ pub fn update_ipv4_blocklist( } else { let not_null_ports = blocked_ports .into_iter() - .filter(|p| (*p != 0 && *p != port)) - .collect::>(); + .filter(|p| (*p != 0 && *p != port)); let mut blocked_ports = [0; MAX_RULES_PORT]; - for (idx, p) in not_null_ports.iter().enumerate() { - blocked_ports[idx] = *p; + for (idx, p) in not_null_ports.enumerate() { + blocked_ports[idx] = p; } if blocked_ports.iter().all(|&port| port == 0) { @@ -98,13 +97,12 @@ pub fn update_ipv6_blocklist( } else { let not_null_ports = blocked_ports .into_iter() - .filter(|p| (*p != 0 && *p != port)) - .collect::>(); + .filter(|p| (*p != 0 && *p != port)); let mut blocked_ports = [0; MAX_RULES_PORT]; - for (idx, p) in not_null_ports.iter().enumerate() { - blocked_ports[idx] = *p; + for (idx, p) in not_null_ports.enumerate() { + blocked_ports[idx] = p; } if blocked_ports.iter().all(|&port| port == 0) { diff --git a/oryx-tui/src/help.rs b/oryx-tui/src/help.rs index bd68290..980e170 100644 --- a/oryx-tui/src/help.rs +++ b/oryx-tui/src/help.rs @@ -119,14 +119,9 @@ impl Help { self.block_height = block.height as usize; let widths = [Constraint::Length(20), Constraint::Fill(1)]; - let rows: Vec = self - .keys - .iter() - .map(|key| { - Row::new(vec![key.0.to_owned(), key.1.into()]) - .style(Style::default().fg(Color::White)) - }) - .collect(); + let rows = self.keys.iter().map(|key| { + Row::new(vec![key.0.to_owned(), key.1.into()]).style(Style::default().fg(Color::White)) + }); let rows_len = self.keys.len().saturating_sub(self.block_height - 6); let table = Table::new(rows, widths).block( diff --git a/oryx-tui/src/interface.rs b/oryx-tui/src/interface.rs index 50b6a09..2c425f5 100644 --- a/oryx-tui/src/interface.rs +++ b/oryx-tui/src/interface.rs @@ -168,40 +168,36 @@ impl Interface { Constraint::Fill(1), ]; - let interfaces: Vec = self - .interfaces - .iter() - .map(|interface| { - let addr = { - match interface - .addresses - .iter() - .find(|a| matches!(a, IpAddr::V4(_) | IpAddr::V6(_))) - { - Some(a) => a.to_string(), - None => String::new(), - } - }; - - let state = if interface.is_up { "Up" } else { "Down" }; - - Row::new(if self.selected_interface.name == interface.name { - vec![ - Line::from(" "), - Line::from(interface.name.clone()), - Line::from(state.to_string()).centered(), - Line::from(addr.clone()), - ] - } else { - vec![ - Line::from(""), - Line::from(interface.name.clone()), - Line::from(state.to_string()).centered(), - Line::from(addr.clone()), - ] - }) + let interfaces = self.interfaces.iter().map(|interface| { + let addr = { + match interface + .addresses + .iter() + .find(|a| matches!(a, IpAddr::V4(_) | IpAddr::V6(_))) + { + Some(a) => a.to_string(), + None => String::new(), + } + }; + + let state = if interface.is_up { "Up" } else { "Down" }; + + Row::new(if self.selected_interface.name == interface.name { + vec![ + Line::from(" "), + Line::from(interface.name.clone()), + Line::from(state.to_string()).centered(), + Line::from(addr.clone()), + ] + } else { + vec![ + Line::from(""), + Line::from(interface.name.clone()), + Line::from(state.to_string()).centered(), + Line::from(addr.clone()), + ] }) - .collect(); + }); let table = Table::new(interfaces, widths) .header( diff --git a/oryx-tui/src/section/metrics.rs b/oryx-tui/src/section/metrics.rs index 41fa775..865859f 100644 --- a/oryx-tui/src/section/metrics.rs +++ b/oryx-tui/src/section/metrics.rs @@ -110,9 +110,7 @@ impl Metrics { pub fn render(&mut self, frame: &mut Frame, block: Rect) { self.window_height = block.height.saturating_sub(4) as usize / 8; - let constraints: Vec = (0..self.window_height) - .map(|_| Constraint::Length(8)) - .collect(); + let constraints = (0..self.window_height).map(|_| Constraint::Length(8)); let chunks = Layout::default() .direction(Direction::Vertical)