39 lines
883 B
Rust
39 lines
883 B
Rust
use maud::Render;
|
|
use std::fmt::{Debug, UpperHex};
|
|
|
|
pub struct DebugRender<T>(pub T);
|
|
|
|
impl<T: Debug> Render for DebugRender<T> {
|
|
fn render_to(&self, w: &mut String) {
|
|
format_args!("{0:#?}", self.0).render_to(w);
|
|
}
|
|
}
|
|
|
|
pub struct Hex<T>(pub T);
|
|
|
|
impl<T: UpperHex> Render for Hex<T> {
|
|
fn render_to(&self, w: &mut String) {
|
|
format_args!("{0:X}", self.0).render_to(w);
|
|
}
|
|
}
|
|
|
|
pub fn size_name(x: u64) -> String {
|
|
if x == 0 {
|
|
format!("0 B")
|
|
} else if x % (1<<10) != 0 {
|
|
format!("{} B", x)
|
|
} else if x % (1<<20) != 0 {
|
|
format!("{} KiB", x / (1<<10))
|
|
} else if x % (1<<30) != 0 {
|
|
format!("{} MiB", x / (1<<20))
|
|
} else if x % (1<<40) != 0 {
|
|
format!("{} GiB", x / (1<<30))
|
|
} else if x % (1<<50) != 0 {
|
|
format!("{} TiB", x / (1<<40))
|
|
} else if x % (1<<60) != 0 {
|
|
format!("{} PiB", x / (1<<50))
|
|
} else {
|
|
format!("{} EiB", x / (1<<60))
|
|
}
|
|
}
|