enable clippy pedantic for nova-stats, fix all warnings

This commit is contained in:
Damocles 2026-04-17 23:28:24 +02:00
parent 64d0172bee
commit e30cae5c7f
5 changed files with 15 additions and 17 deletions

View file

@ -3,6 +3,12 @@ name = "nova-stats"
version = "0.1.0"
edition = "2021"
[lints.clippy]
pedantic = { level = "warn", priority = -1 }
cast_possible_truncation = "allow"
cast_precision_loss = "allow"
cast_sign_loss = "allow"
[[bin]]
name = "nova-stats"
path = "src/main.rs"

View file

@ -56,11 +56,7 @@ pub fn emit_cpu(out: &mut impl Write, prev: &[Sample], curr: &[Sample], freqs: &
return;
}
let usage = prev
.first()
.zip(curr.first())
.map(|(p, c)| pct(p, c))
.unwrap_or(0);
let usage = prev.first().zip(curr.first()).map_or(0, |(p, c)| pct(p, c));
let core_usage: Vec<u32> = prev
.iter()

View file

@ -53,7 +53,7 @@ fn find_amd_hwmon() -> Option<String> {
None
}
fn read_amd(card: &str, hwmon: &Option<String>) -> Option<GpuInfo> {
fn read_amd(card: &str, hwmon: Option<&String>) -> Option<GpuInfo> {
let usage: u32 = fs::read_to_string(format!("{card}/gpu_busy_percent"))
.ok()?
.trim()
@ -70,11 +70,9 @@ fn read_amd(card: &str, hwmon: &Option<String>) -> Option<GpuInfo> {
.parse()
.ok()?;
let temp_c = hwmon
.as_ref()
.and_then(|h| fs::read_to_string(format!("{h}/temp1_input")).ok())
.and_then(|s| s.trim().parse::<i32>().ok())
.map(|mc| mc / 1000)
.unwrap_or(0);
.map_or(0, |mc| mc / 1000);
Some(GpuInfo {
usage,
vram_used_gb: vram_used as f64 / 1_073_741_824.0,
@ -114,7 +112,7 @@ pub fn emit_gpu(out: &mut impl Write, backend: &GpuBackend) {
GpuBackend::Amd {
card_path,
hwmon_path,
} => read_amd(card_path, hwmon_path),
} => read_amd(card_path, hwmon_path.as_ref()),
GpuBackend::Nvidia => read_nvidia(),
GpuBackend::None => return,
};

View file

@ -55,8 +55,8 @@ fn main() {
tick += 1;
let elapsed = t0.elapsed();
if elapsed < interval {
thread::sleep(interval - elapsed);
if let Some(remaining) = interval.checked_sub(elapsed) {
thread::sleep(remaining);
}
}
}

View file

@ -15,9 +15,8 @@ pub fn read_thermal_devices() -> Vec<ThermalDevice> {
let temp_path = format!("/sys/class/thermal/thermal_zone{i}/temp");
let type_path = format!("/sys/class/thermal/thermal_zone{i}/type");
let temp_str = match fs::read_to_string(&temp_path) {
Ok(s) => s,
Err(_) => break,
let Ok(temp_str) = fs::read_to_string(&temp_path) else {
break;
};
let millic: i32 = match temp_str.trim().parse() {
@ -27,8 +26,7 @@ pub fn read_thermal_devices() -> Vec<ThermalDevice> {
let celsius = millic / 1000;
let name = fs::read_to_string(&type_path)
.map(|s| s.trim().to_string())
.unwrap_or_else(|_| format!("zone{i}"));
.map_or_else(|_| format!("zone{i}"), |s| s.trim().to_string());
// Keep the highest temp seen for each device type
let entry = by_name.entry(name).or_insert(celsius);