Closed darrell-roberts closed 3 months ago
So what exactly is this trying to solve? It seems unfortunate that this will need an additional allocation.
The goal was to be able to output HumanBytes
with formatting parameters.
Ex:
#[test]
fn test_human_bytes() {
use std::fmt::Write;
let mut s = String::new();
write!(&mut s, "{:>10}", HumanBytes(10_000)).unwrap();
assert_eq!(s, " 9.77 KiB");
}
I agree though I would not want to incur an additional allocation cost. If there is a better alternative I'd go with that.
I've updated the
Display
implementation forHumanBytes
so it can accept formatting parameters.