use_computing_constants/
lib.rs1#![forbid(unsafe_code)]
2
3pub const BITS_PER_BYTE: usize = 8;
7
8pub const NIBBLE_BITS: usize = 4;
10
11pub const BYTE_VALUES: usize = 256;
13
14pub const KIBIBYTE: usize = 1024;
16
17pub const MEBIBYTE: usize = 1024 * KIBIBYTE;
19
20pub const GIBIBYTE: usize = 1024 * MEBIBYTE;
22
23pub const TEBIBYTE: usize = 1024 * GIBIBYTE;
25
26pub const KILOBYTE: usize = 1000;
28
29pub const MEGABYTE: usize = 1000 * KILOBYTE;
31
32pub const GIGABYTE: usize = 1000 * MEGABYTE;
34
35pub const TERABYTE: usize = 1000 * GIGABYTE;
37
38#[cfg(test)]
39mod tests {
40 use super::{BITS_PER_BYTE, BYTE_VALUES, KIBIBYTE, KILOBYTE, MEBIBYTE, MEGABYTE, NIBBLE_BITS};
41
42 #[test]
43 fn byte_size_relationships_hold() {
44 assert_eq!(BYTE_VALUES, 1usize << BITS_PER_BYTE);
45 assert_eq!(NIBBLE_BITS * 2, BITS_PER_BYTE);
46 }
47
48 #[test]
49 fn binary_storage_relationships_hold() {
50 assert_eq!(MEBIBYTE, 1024 * KIBIBYTE);
51 }
52
53 #[test]
54 fn decimal_storage_relationships_hold() {
55 assert_eq!(MEGABYTE, 1000 * KILOBYTE);
56 }
57}