pipey 0.2.1

A lightweight HTTP-to-WebSocket event delivery service.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/// Formats a count as a human-readable string with optional suffixes (K, M, B).
pub fn format_count(count: u64) -> String {
    fn fmt(value: f64, suffix: &str) -> String {
        let mut s = format!("{value:.1}");
        if s.ends_with(".0") {
            s.truncate(s.len() - 2);
        }
        s.push_str(suffix);
        s
    }

    match count {
        0..=999 => count.to_string(),
        1_000..=999_999 => fmt(count as f64 / 1_000.0, "K"),
        1_000_000..=999_999_999 => fmt(count as f64 / 1_000_000.0, "M"),
        _ => fmt(count as f64 / 1_000_000_000.0, "B"),
    }
}