proxmox-backup-client: use HumanByte to render snapshot size

This commit is contained in:
Dietmar Maurer
2020-10-20 11:43:48 +02:00
parent 6f757b8458
commit 23440482d4
2 changed files with 14 additions and 1 deletions

View File

@ -50,6 +50,19 @@ pub fn render_bool_with_default_true(value: &Value, _record: &Value) -> Result<S
Ok((if value { "1" } else { "0" }).to_string())
}
pub fn render_bytes_human_readable(value: &Value, _record: &Value) -> Result<String, Error> {
if value.is_null() { return Ok(String::new()); }
let text = match value.as_u64() {
Some(bytes) => {
HumanByte::from(bytes).to_string()
}
None => {
value.to_string()
}
};
Ok(text)
}
pub struct HumanByte {
b: usize,
}