Files
soulseek-rs-modded/soulseek-rs/src/ui/utils.rs
T
michel e72c8a5c07 style: crank clippy to pedantic+nursery and fix all lints
Enable the full clippy all + pedantic + nursery groups as workspace warnings,
with a small documented allow-list for the pedantic/nursery lints this project
intentionally does not follow (rustdoc-style requirements, deliberate numeric
casts in the protocol/UI layers, and a few noisy nursery lints). Also enable
the rust unused_lifetimes and unsafe_op_in_unsafe_fn lints.

Fixed every resulting warning (527 -> 0) mechanically per clippy's suggestions:
inline format args, const fns, item ordering, let-else, redundant clones,
map_or, cast_lossless, Eq derives, associated-fn conversions for methods that
never used self, and removing unnecessary Result wrappers whose call sites could
never propagate an error. No runtime behavior changed; cargo fmt applied.

cargo clippy --workspace --all-targets: 0 warnings. All tests pass.
2026-07-19 00:09:17 +02:00

45 lines
1.1 KiB
Rust

use ratatui::{
style::Style,
text::{Line, Span},
};
use crate::ui::COLOR_PRIMARY;
pub const BYTES_PER_MB: f64 = 1_048_576.0;
pub fn format_bytes(bytes: u64) -> String {
let mb = bytes as f64 / BYTES_PER_MB;
format!("{mb:.1} MB")
}
pub fn format_bytes_progress(downloaded: u64, total: u64) -> Line<'static> {
let downloaded_mb = downloaded as f64 / BYTES_PER_MB;
let total_mb = total as f64 / BYTES_PER_MB;
Line::from(vec![
Span::styled(
format!("{downloaded_mb:.1}/{total_mb:.1}"),
Style::default().fg(COLOR_PRIMARY),
),
Span::raw(" MB"),
])
}
pub fn format_speed(speed_bytes_per_sec: f64) -> String {
let mb = speed_bytes_per_sec / BYTES_PER_MB;
format!("{mb:.1} MB/s")
}
pub fn get_bitrate(
attribs: &std::collections::HashMap<u32, u32>,
) -> Option<u32> {
attribs.get(&0).copied()
}
const SPINNER_CHARS: [&str; 10] =
["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
pub const fn get_spinner_char(state: usize) -> &'static str {
SPINNER_CHARS[state % SPINNER_CHARS.len()]
}