Skip to content

Commit e8a6cbb

Browse files
committed
Make clippy happy
1 parent 81b89a2 commit e8a6cbb

File tree

5 files changed

+83
-99
lines changed

5 files changed

+83
-99
lines changed

β€Žbuild.rsβ€Ž

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,38 +45,33 @@ fn get_git_version() -> String {
4545
if let Ok(output) = Command::new("git")
4646
.args(["describe", "--tags", "--dirty", "--always"])
4747
.output()
48+
&& output.status.success()
49+
&& let Ok(version) = String::from_utf8(output.stdout)
4850
{
49-
if output.status.success() {
50-
if let Ok(version) = String::from_utf8(output.stdout) {
51-
let version = version.trim();
52-
// If version doesn't start with 'v' and contains no '-', it's just a commit hash
53-
if !version.starts_with('v') && !version.contains('-') {
54-
// Get Cargo version and append git hash
55-
let cargo_version =
56-
env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string());
57-
return if version.len() >= 7 {
58-
format!("{}-g{}", cargo_version, &version[..7])
59-
} else {
60-
format!("{}-g{}", cargo_version, version)
61-
};
62-
}
63-
return version.to_string();
64-
}
51+
let version = version.trim();
52+
// If version doesn't start with 'v' and contains no '-', it's just a commit hash
53+
if !version.starts_with('v') && !version.contains('-') {
54+
// Get Cargo version and append git hash
55+
let cargo_version =
56+
env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string());
57+
return if version.len() >= 7 {
58+
format!("{}-g{}", cargo_version, &version[..7])
59+
} else {
60+
format!("{}-g{}", cargo_version, version)
61+
};
6562
}
63+
return version.to_string();
6664
}
6765

6866
// Fallback to git rev-parse for just commit hash
6967
if let Ok(output) = Command::new("git")
7068
.args(["rev-parse", "--short", "HEAD"])
7169
.output()
70+
&& output.status.success()
71+
&& let Ok(hash) = String::from_utf8(output.stdout)
7272
{
73-
if output.status.success() {
74-
if let Ok(hash) = String::from_utf8(output.stdout) {
75-
let cargo_version =
76-
env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string());
77-
return format!("{}-g{}", cargo_version, hash.trim());
78-
}
79-
}
73+
let cargo_version = env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string());
74+
return format!("{}-g{}", cargo_version, hash.trim());
8075
}
8176

8277
// Final fallback to Cargo.toml version
@@ -87,12 +82,10 @@ fn get_git_hash() -> String {
8782
if let Ok(output) = Command::new("git")
8883
.args(["rev-parse", "--short", "HEAD"])
8984
.output()
85+
&& output.status.success()
86+
&& let Ok(hash) = String::from_utf8(output.stdout)
9087
{
91-
if output.status.success() {
92-
if let Ok(hash) = String::from_utf8(output.stdout) {
93-
return hash.trim().to_string();
94-
}
95-
}
88+
return hash.trim().to_string();
9689
}
9790

9891
"unknown".to_string()

β€Žsrc/app.rsβ€Ž

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use anyhow::Result;
22
use crossterm::{
33
event::{self, Event, KeyCode},
44
execute,
5-
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
5+
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
66
};
77
use ratatui::{
8+
Terminal,
89
backend::{Backend, CrosstermBackend},
910
layout::Rect,
10-
Terminal,
1111
};
1212
use std::{
1313
io,
@@ -423,12 +423,13 @@ impl App {
423423
self.scroll_modal_down();
424424
} else if matches!(self.active_view, ActiveView::PacketHistory) {
425425
let packet_count = self.get_packet_history().len();
426-
if packet_count > 0 && self.selected_packet_index < packet_count {
427-
if let Some(packet) = self.get_selected_packet() {
428-
self.modal_packet = Some(packet);
429-
self.show_packet_modal = true;
430-
self.modal_scroll_offset = 0;
431-
}
426+
if packet_count > 0
427+
&& self.selected_packet_index < packet_count
428+
&& let Some(packet) = self.get_selected_packet()
429+
{
430+
self.modal_packet = Some(packet);
431+
self.show_packet_modal = true;
432+
self.modal_scroll_offset = 0;
432433
}
433434
}
434435
}
@@ -767,13 +768,13 @@ impl App {
767768
> = std::collections::HashMap::new();
768769

769770
for (i, host) in hosts.iter().enumerate() {
770-
if let PtpHostState::TimeReceiver(receiver_state) = &host.state {
771-
if let Some(transmitter_id) = receiver_state.selected_transmitter_identity {
772-
transmitter_to_receiver_indices
773-
.entry(transmitter_id)
774-
.or_default()
775-
.push(i);
776-
}
771+
if let PtpHostState::TimeReceiver(receiver_state) = &host.state
772+
&& let Some(transmitter_id) = receiver_state.selected_transmitter_identity
773+
{
774+
transmitter_to_receiver_indices
775+
.entry(transmitter_id)
776+
.or_default()
777+
.push(i);
777778
}
778779
}
779780

@@ -989,10 +990,10 @@ impl App {
989990

990991
pub fn get_packet_history(&self) -> Vec<ParsedPacket> {
991992
// Return packets from the currently selected host
992-
if let Some(ref selected_host_id) = self.selected_host_id {
993-
if let Some(history) = self.ptp_tracker.get_host_packet_history(*selected_host_id) {
994-
return history;
995-
}
993+
if let Some(ref selected_host_id) = self.selected_host_id
994+
&& let Some(history) = self.ptp_tracker.get_host_packet_history(*selected_host_id)
995+
{
996+
return history;
996997
}
997998

998999
Vec::new()
@@ -1056,13 +1057,13 @@ impl App {
10561057

10571058
fn restore_host_selection(&mut self) {
10581059
// If we have a stored host ID, try to find it in the current list
1059-
if let Some(ref stored_host_id) = self.selected_host_id {
1060-
if let Some(found_index) = self.find_host_index(*stored_host_id) {
1061-
// Found the stored host, select it
1062-
self.selected_index = found_index;
1063-
self.ensure_host_visible(20);
1064-
return;
1065-
}
1060+
if let Some(ref stored_host_id) = self.selected_host_id
1061+
&& let Some(found_index) = self.find_host_index(*stored_host_id)
1062+
{
1063+
// Found the stored host, select it
1064+
self.selected_index = found_index;
1065+
self.update_selected_host(found_index);
1066+
return;
10661067
}
10671068

10681069
// Either no stored host ID, or stored host not found - clamp current index
@@ -1140,11 +1141,7 @@ impl App {
11401141
pub fn ensure_packet_visible(&mut self) {
11411142
let visible_height = if self.visible_packet_height == 0 {
11421143
// Defensive fallback if height hasn't been set yet
1143-
if self.packet_history_expanded {
1144-
20
1145-
} else {
1146-
8
1147-
}
1144+
if self.packet_history_expanded { 20 } else { 8 }
11481145
} else {
11491146
self.visible_packet_height
11501147
};

β€Žsrc/ptp.rsβ€Ž

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,10 @@ impl PtpTracker {
860860

861861
// Reset all winners in this domain first
862862
for clock_id in &transmitters {
863-
if let Some(host) = self.hosts.get_mut(clock_id) {
864-
if let PtpHostState::TimeTransmitter(ref mut state) = host.state {
865-
state.is_bmca_winner = false;
866-
}
863+
if let Some(host) = self.hosts.get_mut(clock_id)
864+
&& let PtpHostState::TimeTransmitter(ref mut state) = host.state
865+
{
866+
state.is_bmca_winner = false;
867867
}
868868
}
869869

@@ -874,30 +874,28 @@ impl PtpTracker {
874874
if let (Some(best_host), Some(candidate_host)) = (
875875
self.hosts.get(&best_clock_id),
876876
self.hosts.get(&candidate_clock_id),
877-
) {
878-
if let (
879-
PtpHostState::TimeTransmitter(best_state),
880-
PtpHostState::TimeTransmitter(candidate_state),
881-
) = (&best_host.state, &candidate_host.state)
882-
{
883-
let comparison_result = candidate_state.compare_for_bmca(
884-
best_state,
885-
candidate_clock_id,
886-
best_clock_id,
887-
);
888-
889-
if comparison_result == std::cmp::Ordering::Less {
890-
best_clock_id = candidate_clock_id;
891-
}
877+
) && let (
878+
PtpHostState::TimeTransmitter(best_state),
879+
PtpHostState::TimeTransmitter(candidate_state),
880+
) = (&best_host.state, &candidate_host.state)
881+
{
882+
let comparison_result = candidate_state.compare_for_bmca(
883+
best_state,
884+
candidate_clock_id,
885+
best_clock_id,
886+
);
887+
888+
if comparison_result == std::cmp::Ordering::Less {
889+
best_clock_id = candidate_clock_id;
892890
}
893891
}
894892
}
895893

896894
// Mark the winner
897-
if let Some(winner_host) = self.hosts.get_mut(&best_clock_id) {
898-
if let PtpHostState::TimeTransmitter(ref mut state) = winner_host.state {
899-
state.is_bmca_winner = true;
900-
}
895+
if let Some(winner_host) = self.hosts.get_mut(&best_clock_id)
896+
&& let PtpHostState::TimeTransmitter(ref mut state) = winner_host.state
897+
{
898+
state.is_bmca_winner = true;
901899
}
902900

903901
// Update receivers in this domain to select the BMCA winner as their transmitter
@@ -908,11 +906,11 @@ impl PtpTracker {
908906
/// Update all receivers in a domain to select the BMCA winner as their transmitter
909907
fn update_receivers_for_domain(&mut self, domain: u8, winner_clock_id: ClockIdentity) {
910908
for host in self.hosts.values_mut() {
911-
if host.domain_number == Some(domain) {
912-
if let PtpHostState::TimeReceiver(ref mut receiver_state) = host.state {
913-
receiver_state.selected_transmitter_identity = Some(winner_clock_id);
914-
receiver_state.selected_transmitter_confidence = 1.0; // High confidence from BMCA
915-
}
909+
if host.domain_number == Some(domain)
910+
&& let PtpHostState::TimeReceiver(ref mut receiver_state) = host.state
911+
{
912+
receiver_state.selected_transmitter_identity = Some(winner_clock_id);
913+
receiver_state.selected_transmitter_confidence = 1.0; // High confidence from BMCA
916914
}
917915
}
918916
}

β€Žsrc/source.rsβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ async fn capture_on_interface(
306306
loop {
307307
match rx.next() {
308308
Ok(packet_data) => {
309-
if let Some(raw_packet) = process_ethernet_packet(packet_data, &interface_name) {
310-
if sender.send(raw_packet).is_err() {
311-
// Receiver has been dropped, exit the loop
312-
break;
313-
}
309+
if let Some(raw_packet) = process_ethernet_packet(packet_data, &interface_name)
310+
&& sender.send(raw_packet).is_err()
311+
{
312+
// Receiver has been dropped, exit the loop
313+
break;
314314
}
315315
}
316316
Err(e) => {

β€Žsrc/ui.rsβ€Ž

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use ratatui::{
2+
Frame,
23
layout::{Alignment, Constraint, Direction, Layout, Rect},
34
style::{Color, Modifier, Style},
45
text::{Line, Span},
56
widgets::{Block, BorderType, Borders, Cell, Clear, Paragraph, Row, Table, Wrap},
6-
Frame,
77
};
88

99
use crate::{
1010
app::{ActiveView, App, SortColumn, TreeNode},
1111
ptp::{PtpHost, PtpHostState},
12-
types::{format_timestamp, ParsedPacket, PtpClockAccuracy, PtpClockClass},
12+
types::{ParsedPacket, PtpClockAccuracy, PtpClockClass, format_timestamp},
1313
version,
1414
};
1515

@@ -383,11 +383,7 @@ fn render_hosts_table(f: &mut Frame, area: Rect, app: &mut App) {
383383
// Create indentation for tree structure
384384
let indent = " ".repeat(node.depth);
385385
let tree_prefix = if node.depth > 0 {
386-
if *is_last_child {
387-
"└─ "
388-
} else {
389-
"β”œβ”€ "
390-
}
386+
if *is_last_child { "└─ " } else { "β”œβ”€ " }
391387
} else {
392388
""
393389
};

0 commit comments

Comments
Β (0)