| 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 | macro_rules! define_sizes {
|
| 36 | ($($type:ty),* $(,)?) => {
|
| 37 | define_sizes!(@internal [$($type),*]
|
| 38 | /// `0x0000_0400`.
|
| 39 | SZ_1K,
|
| 40 | /// `0x0000_0800`.
|
| 41 | SZ_2K,
|
| 42 | /// `0x0000_1000`.
|
| 43 | SZ_4K,
|
| 44 | /// `0x0000_2000`.
|
| 45 | SZ_8K,
|
| 46 | /// `0x0000_4000`.
|
| 47 | SZ_16K,
|
| 48 | /// `0x0000_8000`.
|
| 49 | SZ_32K,
|
| 50 | /// `0x0001_0000`.
|
| 51 | SZ_64K,
|
| 52 | /// `0x0002_0000`.
|
| 53 | SZ_128K,
|
| 54 | /// `0x0004_0000`.
|
| 55 | SZ_256K,
|
| 56 | /// `0x0008_0000`.
|
| 57 | SZ_512K,
|
| 58 | /// `0x0010_0000`.
|
| 59 | SZ_1M,
|
| 60 | /// `0x0020_0000`.
|
| 61 | SZ_2M,
|
| 62 | /// `0x0040_0000`.
|
| 63 | SZ_4M,
|
| 64 | /// `0x0080_0000`.
|
| 65 | SZ_8M,
|
| 66 | /// `0x0100_0000`.
|
| 67 | SZ_16M,
|
| 68 | /// `0x0200_0000`.
|
| 69 | SZ_32M,
|
| 70 | /// `0x0400_0000`.
|
| 71 | SZ_64M,
|
| 72 | /// `0x0800_0000`.
|
| 73 | SZ_128M,
|
| 74 | /// `0x1000_0000`.
|
| 75 | SZ_256M,
|
| 76 | /// `0x2000_0000`.
|
| 77 | SZ_512M,
|
| 78 | /// `0x4000_0000`.
|
| 79 | SZ_1G,
|
| 80 | /// `0x8000_0000`.
|
| 81 | SZ_2G,
|
| 82 | );
|
| 83 | };
|
| 84 |
|
| 85 | (@internal [$($type:ty),*] $($names_and_metas:tt)*) => {
|
| 86 | define_sizes!(@consts_and_trait $($names_and_metas)*);
|
| 87 | define_sizes!(@impls [$($type),*] $($names_and_metas)*);
|
| 88 | };
|
| 89 |
|
| 90 | (@consts_and_trait $($(#[$meta:meta])* $name:ident,)*) => {
|
| 91 | $(
|
| 92 | $(#[$meta])*
|
| 93 | pub const $name: usize = bindings::$name as usize;
|
| 94 | )*
|
| 95 |
|
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | pub trait SizeConstants {
|
| 111 | $(
|
| 112 | $(#[$meta])*
|
| 113 | const $name: Self;
|
| 114 | )*
|
| 115 | }
|
| 116 | };
|
| 117 |
|
| 118 | (@impls [] $($(#[$meta:meta])* $name:ident,)*) => {};
|
| 119 |
|
| 120 | (@impls [$first:ty $(, $rest:ty)*] $($(#[$meta:meta])* $name:ident,)*) => {
|
| 121 | impl SizeConstants for $first {
|
| 122 | $(
|
| 123 | const $name: Self = {
|
| 124 | assert!((self::$name as u128) <= (<$first>::MAX as u128));
|
| 125 | self::$name as $first
|
| 126 | };
|
| 127 | )*
|
| 128 | }
|
| 129 |
|
| 130 | define_sizes!(@impls [$($rest),*] $($(#[$meta])* $name,)*);
|
| 131 | };
|
| 132 | }
|
| 133 |
|
| 134 | define_sizes!(u32, u64, usize);
|