MCPcopy Create free account
hub / github.com/caffienerd/struct-cli / format_size

Function format_size

src/utils.rs:6–20  ·  view source on GitHub ↗

Format bytes into human-readable size (B, K, M, G)

(bytes: u64)

Source from the content-addressed store, hash-verified

4
5/// Format bytes into human-readable size (B, K, M, G)
6pub fn format_size(bytes: u64) -> String {
7 const KB: u64 = 1024;
8 const MB: u64 = KB * 1024;
9 const GB: u64 = MB * 1024;
10
11 if bytes >= GB {
12 format!("{:.1}G", bytes as f64 / GB as f64)
13 } else if bytes >= MB {
14 format!("{:.1}M", bytes as f64 / MB as f64)
15 } else if bytes >= KB {
16 format!("{:.1}K", bytes as f64 / KB as f64)
17 } else {
18 format!("{}B", bytes)
19 }
20}
21
22/// Check if a file is executable
23pub fn is_executable(path: &Path) -> bool {

Callers 2

display_treeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected