byte_unit/byte/
constants.rs

1use super::Byte;
2#[cfg(feature = "u128")]
3use super::RONNABYTE;
4
5/// Constant `Byte`s.
6#[rustfmt::skip]
7impl Byte {
8    /// One byte.
9    pub const BYTE: Byte = Byte(1);
10
11    /// 1 KB = 10<sup>3</sup> bytes.
12    pub const KILOBYTE: Byte = Byte(1_000);
13    /// 1 MB = 10<sup>6</sup> bytes.
14    pub const MEGABYTE: Byte = Byte(1_000_000);
15    /// 1 GB = 10<sup>9</sup> bytes.
16    pub const GIGABYTE: Byte = Byte(1_000_000_000);
17    /// 1 TB = 10<sup>12</sup> bytes.
18    pub const TERABYTE: Byte = Byte(1_000_000_000_000);
19    /// 1 PB = 10<sup>15</sup> bytes.
20    pub const PETABYTE: Byte = Byte(1_000_000_000_000_000);
21    /// 1 EB = 10<sup>18</sup> bytes.
22    pub const EXABYTE: Byte = Byte(1_000_000_000_000_000_000);
23    #[cfg(feature = "u128")]
24    /// 1 ZB = 10<sup>21</sup> bytes.
25    pub const ZETTABYTE: Byte = Byte(1_000_000_000_000_000_000_000);
26    #[cfg(feature = "u128")]
27    /// 1 YB = 10<sup>24</sup> bytes.
28    pub const YOTTABYTE: Byte = Byte(1_000_000_000_000_000_000_000_000);
29
30    /// 1 KiB = 2<sup>10</sup> bytes.
31    pub const KIBIBYTE: Byte = Byte(1 << 10);
32    /// 1 MiB = 2<sup>20</sup> bytes.
33    pub const MEBIBYTE: Byte = Byte(1 << 20);
34    /// 1 GiB = 2<sup>30</sup> bytes.
35    pub const GIBIBYTE: Byte = Byte(1 << 30);
36    /// 1 TiB = 2<sup>40</sup> bytes.
37    pub const TEBIBYTE: Byte = Byte(1 << 40);
38    /// 1 PiB = 2<sup>50</sup> bytes.
39    pub const PEBIBYTE: Byte = Byte(1 << 50);
40    /// 1 EiB = 2<sup>60</sup> bytes.
41    pub const EXBIBYTE: Byte = Byte(1 << 60);
42    #[cfg(feature = "u128")]
43    /// 1 ZiB = 2<sup>70</sup> bytes.
44    pub const ZEBIBYTE: Byte = Byte(1 << 70);
45    #[cfg(feature = "u128")]
46    /// 1 YiB = 2<sup>80</sup> bytes.
47    pub const YOBIBYTE: Byte = Byte(1 << 80);
48
49
50    /// 1 Kbit = 125 bytes.
51    pub const KILOBIT: Byte = Byte::KILOBYTE.div_8();
52    /// 1 Mbit = 125 * 10<sup>3</sup> bytes.
53    pub const MEGABIT: Byte = Byte::MEGABYTE.div_8();
54    /// 1 Gbit = 125 * 10<sup>6</sup> bytes.
55    pub const GIGABIT: Byte = Byte::GIGABYTE.div_8();
56    /// 1 Tbit = 125 * 10<sup>9</sup> bytes.
57    pub const TERABIT: Byte = Byte::TERABYTE.div_8();
58    /// 1 Pbit = 125 * 10<sup>12</sup> bytes.
59    pub const PETABIT: Byte = Byte::PETABYTE.div_8();
60    /// 1 Ebit = 125 * 10<sup>15</sup> bytes.
61    pub const EXABIT: Byte = Byte::EXABYTE.div_8();
62    #[cfg(feature = "u128")]
63    /// 1 Zbit = 125 * 10<sup>18</sup> bytes.
64    pub const ZETTABIT: Byte = Byte::ZETTABYTE.div_8();
65    #[cfg(feature = "u128")]
66    /// 1 Ybit = 125 * 10<sup>21</sup> bytes.
67    pub const YOTTABIT: Byte = Byte::YOTTABYTE.div_8();
68
69
70    /// 1 Kibit = 2<sup>7</sup> bytes.
71    pub const KIBIBIT: Byte = Byte::KIBIBYTE.div_8();
72    /// 1 Mibit = 2<sup>17</sup> bytes.
73    pub const MEBIBIT: Byte = Byte::MEBIBYTE.div_8();
74    /// 1 Gibit = 2<sup>27</sup> bytes.
75    pub const GIBIBIT: Byte = Byte::GIBIBYTE.div_8();
76    /// 1 Tibit = 2<sup>37</sup> bytes.
77    pub const TEBIBIT: Byte = Byte::TEBIBYTE.div_8();
78    /// 1 Pibit = 2<sup>47</sup> bytes.
79    pub const PEBIBIT: Byte = Byte::PEBIBYTE.div_8();
80    /// 1 Eibit = 2<sup>57</sup> bytes.
81    pub const EXBIBIT: Byte = Byte::EXBIBYTE.div_8();
82    #[cfg(feature = "u128")]
83    /// 1 Zibit = 2<sup>67</sup> bytes.
84    pub const ZEBIBIT: Byte = Byte::ZEBIBYTE.div_8();
85    #[cfg(feature = "u128")]
86    /// 1 Yibit = 2<sup>77</sup> bytes.
87    pub const YOBIBIT: Byte = Byte::YOBIBYTE.div_8();
88
89    /// 0 byte.
90    pub const MIN: Byte = Byte(0);
91    /// **10<sup>27</sup> - 1** bytes if the `u128` feature is enabled, or **2<sup>64</sup> - 1** otherwise.
92    pub const MAX: Byte = {
93        #[cfg(feature = "u128")]
94        {
95            Byte(RONNABYTE - 1)
96        }
97
98        #[cfg(not(feature = "u128"))]
99        {
100            Byte(u64::MAX)
101        }
102    };
103}