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

View File

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

View File

@ -180,8 +180,9 @@ pub fn per_core_handle_scrollbar_mouse(
}
}
MouseEventKind::Drag(MouseButton::Left) => {
if let Some(mut d) = drag.take() {
if d.active {
if let Some(mut d) = drag.take()
&& d.active
{
let dy = (mouse.row as i32) - (d.start_y as i32);
let new_top = (d.start_top as i32 + dy)
.clamp(0, (track.saturating_sub(thumb_len)) as i32)
@ -203,7 +204,6 @@ pub fn per_core_handle_scrollbar_mouse(
*drag = Some(d);
}
}
}
MouseEventKind::Up(MouseButton::Left) => {
// End drag
*drag = None;