Ferrit Explore
中文·繁體·EN·日本語 Sign in Register
cielxl / veld / src / util / mod.rs
pub mod buffer;
pub mod path;
pub mod signal;

/// Format a byte size into a human-readable string
pub fn human_readable_size(bytes: u64) -> String {
    const UNITS: [&str; 5] = ["B", "KB", "MB", "GB", "TB"];
    let mut size = bytes as f64;
    for unit in &UNITS {
        if size < 1024.0 {
            return format!("{:.1} {}", size, unit);
        }
        size /= 1024.0;
    }
    format!("{:.1} PB", size)
}

/// Get the number of available CPU cores
pub fn num_cpus() -> usize {
    num_cpus::get()
}