mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
begin Titan protocol implementation
This commit is contained in:
parent
236d941b37
commit
879fe7a6f6
37 changed files with 609 additions and 102 deletions
23
src/tool.rs
Normal file
23
src/tool.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
//! Some shared helpers collection
|
||||
|
||||
/// Format bytes to KB/MB/GB presentation
|
||||
pub fn format_bytes(value: usize) -> String {
|
||||
const KB: f32 = 1024.0;
|
||||
const MB: f32 = KB * KB;
|
||||
const GB: f32 = MB * KB;
|
||||
|
||||
let f = value as f32;
|
||||
|
||||
if f < KB {
|
||||
format!(
|
||||
"{value} {}",
|
||||
plurify::ns(value, &["byte", "bytes", "bytes"])
|
||||
)
|
||||
} else if f < MB {
|
||||
format!("{:.2} KB", f / KB)
|
||||
} else if f < GB {
|
||||
format!("{:.2} MB", f / MB)
|
||||
} else {
|
||||
format!("{:.2} GB", f / GB)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue