1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt::{self, Display, Formatter};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ByteUnit {
B,
KB,
KiB,
MB,
MiB,
GB,
GiB,
TB,
TiB,
PB,
PiB,
}
impl Display for ByteUnit {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
match self {
ByteUnit::B => f.write_str("B"),
ByteUnit::KB => f.write_str("KB"),
ByteUnit::KiB => f.write_str("KiB"),
ByteUnit::MB => f.write_str("MB"),
ByteUnit::MiB => f.write_str("MiB"),
ByteUnit::GB => f.write_str("GB"),
ByteUnit::GiB => f.write_str("GiB"),
ByteUnit::TB => f.write_str("TB"),
ByteUnit::TiB => f.write_str("TiB"),
ByteUnit::PB => f.write_str("PB"),
ByteUnit::PiB => f.write_str("PiB"),
}
}
}