Fix clippy warnings: collapse nested if statements using let-else patterns

This commit is contained in:
jasonwitty 2025-09-04 05:58:17 -07:00
parent a9bf4208ab
commit 764c25846f
3 changed files with 49 additions and 51 deletions

View File

@ -269,16 +269,15 @@ impl App {
// Processes table: sort by column on header click // Processes table: sort by column on header click
if let (Some(mm), Some(p_area)) = if let (Some(mm), Some(p_area)) =
(self.last_metrics.as_ref(), self.last_procs_area) (self.last_metrics.as_ref(), self.last_procs_area)
{ && let Some(new_sort) = processes_handle_mouse(
if let Some(new_sort) = processes_handle_mouse(
&mut self.procs_scroll_offset, &mut self.procs_scroll_offset,
&mut self.procs_drag, &mut self.procs_drag,
m, m,
p_area, p_area,
mm.top_processes.len(), mm.top_processes.len(),
) { )
self.procs_sort_by = new_sort; {
} self.procs_sort_by = new_sort;
} }
} }
Event::Resize(_, _) => {} Event::Resize(_, _) => {}
@ -299,21 +298,20 @@ impl App {
if self.last_procs_poll.elapsed() >= self.procs_interval { if self.last_procs_poll.elapsed() >= self.procs_interval {
if let Ok(AgentResponse::Processes(procs)) = if let Ok(AgentResponse::Processes(procs)) =
ws.request(AgentRequest::Processes).await ws.request(AgentRequest::Processes).await
&& let Some(mm) = self.last_metrics.as_mut()
{ {
if let Some(mm) = self.last_metrics.as_mut() { mm.top_processes = procs.top_processes;
mm.top_processes = procs.top_processes; mm.process_count = Some(procs.process_count);
mm.process_count = Some(procs.process_count);
}
} }
self.last_procs_poll = Instant::now(); self.last_procs_poll = Instant::now();
} }
// Only poll disks every 5s // Only poll disks every 5s
if self.last_disks_poll.elapsed() >= self.disks_interval { if self.last_disks_poll.elapsed() >= self.disks_interval {
if let Ok(AgentResponse::Disks(disks)) = ws.request(AgentRequest::Disks).await { if let Ok(AgentResponse::Disks(disks)) = ws.request(AgentRequest::Disks).await
if let Some(mm) = self.last_metrics.as_mut() { && let Some(mm) = self.last_metrics.as_mut()
mm.disks = disks; {
} mm.disks = disks;
} }
self.last_disks_poll = Instant::now(); self.last_disks_poll = Instant::now();
} }

View File

@ -71,17 +71,17 @@ pub(crate) fn parse_args<I: IntoIterator<Item = String>>(args: I) -> Result<Pars
processes_interval_ms = it.next().and_then(|v| v.parse().ok()); processes_interval_ms = it.next().and_then(|v| v.parse().ok());
} }
_ if arg.starts_with("--tls-ca=") => { _ if arg.starts_with("--tls-ca=") => {
if let Some((_, v)) = arg.split_once('=') { if let Some((_, v)) = arg.split_once('=')
if !v.is_empty() { && !v.is_empty()
tls_ca = Some(v.to_string()); {
} tls_ca = Some(v.to_string());
} }
} }
_ if arg.starts_with("--profile=") => { _ if arg.starts_with("--profile=") => {
if let Some((_, v)) = arg.split_once('=') { if let Some((_, v)) = arg.split_once('=')
if !v.is_empty() { && !v.is_empty()
profile = Some(v.to_string()); {
} profile = Some(v.to_string());
} }
} }
_ if arg.starts_with("--metrics-interval-ms=") => { _ if arg.starts_with("--metrics-interval-ms=") => {
@ -416,16 +416,16 @@ fn spawn_demo_agent(port: u16) -> Result<DemoGuard, Box<dyn std::error::Error>>
}) })
} }
fn find_agent_executable() -> std::path::PathBuf { fn find_agent_executable() -> std::path::PathBuf {
if let Ok(exe) = std::env::current_exe() { if let Ok(exe) = std::env::current_exe()
if let Some(parent) = exe.parent() { && let Some(parent) = exe.parent()
#[cfg(windows)] {
let name = "socktop_agent.exe"; #[cfg(windows)]
#[cfg(not(windows))] let name = "socktop_agent.exe";
let name = "socktop_agent"; #[cfg(not(windows))]
let candidate = parent.join(name); let name = "socktop_agent";
if candidate.exists() { let candidate = parent.join(name);
return candidate; if candidate.exists() {
} return candidate;
} }
} }
std::path::PathBuf::from("socktop_agent") std::path::PathBuf::from("socktop_agent")

View File

@ -180,28 +180,28 @@ pub fn per_core_handle_scrollbar_mouse(
} }
} }
MouseEventKind::Drag(MouseButton::Left) => { MouseEventKind::Drag(MouseButton::Left) => {
if let Some(mut d) = drag.take() { if let Some(mut d) = drag.take()
if d.active { && d.active
let dy = (mouse.row as i32) - (d.start_y as i32); {
let new_top = (d.start_top as i32 + dy) let dy = (mouse.row as i32) - (d.start_y as i32);
.clamp(0, (track.saturating_sub(thumb_len)) as i32) let new_top = (d.start_top as i32 + dy)
as usize; .clamp(0, (track.saturating_sub(thumb_len)) as i32)
// Inverse mapping top -> offset as usize;
if track > thumb_len { // Inverse mapping top -> offset
let denom = track - thumb_len; if track > thumb_len {
offset = if max_off == 0 { let denom = track - thumb_len;
0 offset = if max_off == 0 {
} else { 0
(new_top * max_off + denom / 2) / denom
};
} else { } else {
offset = 0; (new_top * max_off + denom / 2) / denom
} };
// Keep dragging } else {
d.start_top = new_top; offset = 0;
d.start_y = mouse.row;
*drag = Some(d);
} }
// Keep dragging
d.start_top = new_top;
d.start_y = mouse.row;
*drag = Some(d);
} }
} }
MouseEventKind::Up(MouseButton::Left) => { MouseEventKind::Up(MouseButton::Left) => {