| 1 | #[allow (dead_code)] |
| 2 | #[allow (path_statements)] |
| 3 | pub(crate) const fn smaller_than<const N: usize, const MAX: usize>() { |
| 4 | Assert::<N, MAX>::LESS; |
| 5 | } |
| 6 | |
| 7 | #[allow (dead_code)] |
| 8 | #[allow (path_statements)] |
| 9 | pub(crate) const fn greater_than_eq_0<const N: usize>() { |
| 10 | Assert::<N, 0>::GREATER_EQ; |
| 11 | } |
| 12 | |
| 13 | #[allow (dead_code)] |
| 14 | #[allow (path_statements)] |
| 15 | pub(crate) const fn greater_than_0<const N: usize>() { |
| 16 | Assert::<N, 0>::GREATER; |
| 17 | } |
| 18 | |
| 19 | #[allow (dead_code)] |
| 20 | #[allow (path_statements)] |
| 21 | pub(crate) const fn greater_than_1<const N: usize>() { |
| 22 | Assert::<N, 1>::GREATER; |
| 23 | } |
| 24 | |
| 25 | #[allow (dead_code)] |
| 26 | #[allow (path_statements)] |
| 27 | pub(crate) const fn power_of_two<const N: usize>() { |
| 28 | Assert::<N, 0>::GREATER; |
| 29 | Assert::<N, 0>::POWER_OF_TWO; |
| 30 | } |
| 31 | |
| 32 | #[allow (dead_code)] |
| 33 | /// Const assert hack |
| 34 | pub struct Assert<const L: usize, const R: usize>; |
| 35 | |
| 36 | #[allow (dead_code)] |
| 37 | impl<const L: usize, const R: usize> Assert<L, R> { |
| 38 | /// Const assert hack |
| 39 | pub const GREATER_EQ: usize = L - R; |
| 40 | |
| 41 | /// Const assert hack |
| 42 | pub const LESS_EQ: usize = R - L; |
| 43 | |
| 44 | /// Const assert hack |
| 45 | pub const NOT_EQ: isize = 0 / (R as isize - L as isize); |
| 46 | |
| 47 | /// Const assert hack |
| 48 | pub const EQ: usize = (R - L) + (L - R); |
| 49 | |
| 50 | /// Const assert hack |
| 51 | pub const GREATER: usize = L - R - 1; |
| 52 | |
| 53 | /// Const assert hack |
| 54 | pub const LESS: usize = R - L - 1; |
| 55 | |
| 56 | /// Const assert hack |
| 57 | pub const POWER_OF_TWO: usize = 0 - (L & (L - 1)); |
| 58 | } |
| 59 | |