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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
pub(crate) mod private {
pub trait Sealed {}
}
macro_rules! impl_sealed_for {
( $($primitive:ty),* ) => {
$(
impl private::Sealed for $primitive {}
)*
}
}
impl_sealed_for!(bool, u8, u16, u32, u64, u128);
pub trait TotalSizeIsMultipleOfEightBits: private::Sealed {}
pub trait TotalSizeIsNotMultipleOfEightBits: private::Sealed {}
pub trait RenameSizeType: private::Sealed {
type CheckType;
}
pub struct TotalSize<T>(::core::marker::PhantomData<T>);
macro_rules! impl_total_size_for {
( $(($n:expr, $name:ident)),* ) => {
$(
pub enum $name {}
impl private::Sealed for TotalSize<[(); $n]> {}
impl private::Sealed for $name {}
impl RenameSizeType for TotalSize<[(); $n]> {
type CheckType = $name;
}
)*
}
}
impl_total_size_for!(
(0, ZeroMod8),
(1, OneMod8),
(2, TwoMod8),
(3, ThreeMod8),
(4, FourMod8),
(5, FiveMod8),
(6, SixMod8),
(7, SevenMod8)
);
impl TotalSizeIsMultipleOfEightBits for ZeroMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for OneMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for TwoMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for ThreeMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for FourMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for FiveMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for SixMod8 {}
impl TotalSizeIsNotMultipleOfEightBits for SevenMod8 {}
pub trait CheckTotalSizeMultipleOf8
where
<Self::Size as RenameSizeType>::CheckType: TotalSizeIsMultipleOfEightBits,
{
type Size: RenameSizeType;
}
pub trait CheckTotalSizeIsNotMultipleOf8
where
<Self::Size as RenameSizeType>::CheckType: TotalSizeIsNotMultipleOfEightBits,
{
type Size: RenameSizeType;
}
pub trait DiscriminantInRange: private::Sealed {}
pub trait SpecifierHasAtMost128Bits: private::Sealed {}
pub enum True {}
pub enum False {}
impl private::Sealed for True {}
impl DiscriminantInRange for True {}
impl SpecifierHasAtMost128Bits for True {}
impl FillsUnalignedBits for True {}
impl DoesNotFillUnalignedBits for True {}
pub trait DispatchTrueFalse: private::Sealed {
type Out;
}
impl private::Sealed for [(); 0] {}
impl DispatchTrueFalse for [(); 0] {
type Out = False;
}
impl DispatchTrueFalse for [(); 1] {
type Out = True;
}
pub trait CheckDiscriminantInRange<A>
where
<Self::CheckType as DispatchTrueFalse>::Out: DiscriminantInRange,
{
type CheckType: DispatchTrueFalse;
}
pub trait CheckSpecifierHasAtMost128Bits
where
<Self::CheckType as DispatchTrueFalse>::Out: SpecifierHasAtMost128Bits,
{
type CheckType: DispatchTrueFalse;
}
pub struct BitsCheck<A> {
pub arr: A,
}
pub trait CheckFillsUnalignedBits
where
<Self::CheckType as DispatchTrueFalse>::Out: FillsUnalignedBits,
{
type CheckType: DispatchTrueFalse;
}
pub trait FillsUnalignedBits {}
pub trait CheckDoesNotFillUnalignedBits
where
<Self::CheckType as DispatchTrueFalse>::Out: DoesNotFillUnalignedBits,
{
type CheckType: DispatchTrueFalse;
}
pub trait DoesNotFillUnalignedBits {}