From f4f3385ff760f6570ae7af93774748e977da30e4 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 17 Nov 2025 18:17:59 +0300 Subject: [PATCH] various: fix clippy warnings - Adds proper documentation comments with `# Errors` sections for all functions returning `Result` - `cast_precision_loss` on `u64` -> `f64` for disk sizes is acceptable since disk sizes won't exceed f64's precision limit in practice. Thus, we can suppress those. - `cast_sign_loss` and `cast_possible_truncation` on the percentage calculation is safe since percentages are always 0-100. Once again, it's safe to suppress. Signed-off-by: NotAShelf Change-Id: Id4dd7ebc9674407d2be4f38ff4de24bc6a6a6964 --- src/release.rs | 5 +++++ src/system.rs | 12 ++++++++++++ src/uptime.rs | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/src/release.rs b/src/release.rs index d9ec4c9..1b820b8 100644 --- a/src/release.rs +++ b/src/release.rs @@ -21,6 +21,11 @@ pub fn get_system_info(utsname: &UtsName) -> String { result } +/// Gets the pretty name of the OS from `/etc/os-release`. +/// +/// # Errors +/// +/// Returns an error if `/etc/os-release` cannot be read. #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn get_os_pretty_name() -> Result { // We use a stack-allocated buffer here, which seems to perform MUCH better diff --git a/src/system.rs b/src/system.rs index 21b2b2f..ba90b27 100644 --- a/src/system.rs +++ b/src/system.rs @@ -49,7 +49,13 @@ pub fn get_shell() -> String { .to_owned() } +/// Gets the root disk usage information. +/// +/// # Errors +/// +/// Returns an error if the filesystem information cannot be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] +#[allow(clippy::cast_precision_loss)] pub fn get_root_disk_usage() -> Result { let vfs = statvfs("/")?; let block_size = vfs.block_size() as u64; @@ -75,6 +81,11 @@ pub fn get_root_disk_usage() -> Result { Ok(result) } +/// Gets the system memory usage information. +/// +/// # Errors +/// +/// Returns an error if `/proc/meminfo` cannot be read. #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn get_memory_usage() -> Result { #[cfg_attr(feature = "hotpath", hotpath::measure)] @@ -109,6 +120,7 @@ pub fn get_memory_usage() -> Result { } let (used_memory, total_memory) = parse_memory_info()?; + #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] let percentage_used = (used_memory / total_memory * 100.0).round() as u64; let mut result = String::with_capacity(64); diff --git a/src/uptime.rs b/src/uptime.rs index bd2cc39..72af399 100644 --- a/src/uptime.rs +++ b/src/uptime.rs @@ -1,5 +1,10 @@ use std::{fmt::Write, io, mem::MaybeUninit}; +/// Gets the current system uptime. +/// +/// # Errors +/// +/// Returns an error if the system uptime cannot be retrieved. #[cfg_attr(feature = "hotpath", hotpath::measure)] pub fn get_current() -> Result { let uptime_seconds = { @@ -7,6 +12,7 @@ pub fn get_current() -> Result { if unsafe { libc::sysinfo(info.as_mut_ptr()) } != 0 { return Err(io::Error::last_os_error()); } + #[allow(clippy::cast_sign_loss)] unsafe { info.assume_init().uptime as u64 } };