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 <raf@notashelf.dev>
Change-Id: Id4dd7ebc9674407d2be4f38ff4de24bc6a6a6964
This commit is contained in:
raf 2025-11-17 18:17:59 +03:00
commit f4f3385ff7
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 23 additions and 0 deletions

View file

@ -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<String, io::Error> {
let uptime_seconds = {
@ -7,6 +12,7 @@ pub fn get_current() -> Result<String, io::Error> {
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 }
};