1#[repr(u64)]
5#[derive(Clone, Copy, PartialEq, Eq, Default, PartialOrd, Ord, Hash, Debug)]
6pub enum ByteScale {
7 B = 1,
9 #[default]
11 KB = 1024,
12 MB = Self::KB as u64 * 1024,
14 GB = Self::MB as u64 * 1024,
16 TB = Self::GB as u64 * 1024,
18 PB = Self::TB as u64 * 1024,
20 EB = Self::PB as u64 * 1024,
22}
23
24impl Into<u64> for ByteScale {
25 fn into(self) -> u64 {
26 self as _
27 }
28}
29
30impl Into<usize> for ByteScale {
31 fn into(self) -> usize {
32 #[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))]
33 assert!(self < Self::MB, "pointer width not 32 or 64");
34
35 #[cfg(not(target_pointer_width = "64"))]
36 assert!(self < Self::TB, "pointer width not 64");
37
38 self as _
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn sizes() {
48 println!("{}", ByteScale::MB as u64);
49 println!("{}", ByteScale::GB as u64);
50 println!("{}", ByteScale::TB as u64);
51 println!("{}", ByteScale::PB as u64);
52 println!("{}", ByteScale::EB as u64);
53 }
54}