1use zerocopy::{IntoBytes, TryFromBytes};
9
10#[repr(u8)]
11#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
12pub enum Color {
13 Red = 0,
14 Orange = 1,
15 Yellow = 2,
16 Green = 3,
17 Blue = 4,
18 Indigo = 5,
19 Violet = 6,
20}
21
22impl Color {
23 pub fn from_raw(raw: u8) -> Option<Self> {
24 match raw {
25 0 => Some(Self::Red),
26
27 1 => Some(Self::Orange),
28
29 2 => Some(Self::Yellow),
30
31 3 => Some(Self::Green),
32
33 4 => Some(Self::Blue),
34
35 5 => Some(Self::Indigo),
36
37 6 => Some(Self::Violet),
38
39 _ => None,
40 }
41 }
42}
43
44impl From<Color> for u8 {
45 fn from(val: Color) -> Self {
46 val as Self
47 }
48}
49
50#[repr(u8)]
51#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
52pub enum Uint8Limits {
53 Min = 0,
54 Max = 0b11111111,
55}
56
57impl Uint8Limits {
58 pub fn from_raw(raw: u8) -> Option<Self> {
59 match raw {
60 0 => Some(Self::Min),
61
62 0b11111111 => Some(Self::Max),
63
64 _ => None,
65 }
66 }
67}
68
69impl From<Uint8Limits> for u8 {
70 fn from(val: Uint8Limits) -> Self {
71 val as Self
72 }
73}
74
75#[repr(u16)]
76#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
77pub enum Uint16Limits {
78 Min = 0,
79 Max = 0xffff,
80}
81
82impl Uint16Limits {
83 pub fn from_raw(raw: u16) -> Option<Self> {
84 match raw {
85 0 => Some(Self::Min),
86
87 0xffff => Some(Self::Max),
88
89 _ => None,
90 }
91 }
92}
93
94impl From<Uint16Limits> for u16 {
95 fn from(val: Uint16Limits) -> Self {
96 val as Self
97 }
98}
99
100#[repr(u32)]
101#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
102pub enum Uint32Limits {
103 Min = 0,
104 Max = 0xffffffff,
105}
106
107impl Uint32Limits {
108 pub fn from_raw(raw: u32) -> Option<Self> {
109 match raw {
110 0 => Some(Self::Min),
111
112 0xffffffff => Some(Self::Max),
113
114 _ => None,
115 }
116 }
117}
118
119impl From<Uint32Limits> for u32 {
120 fn from(val: Uint32Limits) -> Self {
121 val as Self
122 }
123}
124
125#[repr(u64)]
126#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
127pub enum Uint64Limits {
128 Min = 0,
129 Max = 0xffffffffffffffff,
130}
131
132impl Uint64Limits {
133 pub fn from_raw(raw: u64) -> Option<Self> {
134 match raw {
135 0 => Some(Self::Min),
136
137 0xffffffffffffffff => Some(Self::Max),
138
139 _ => None,
140 }
141 }
142}
143
144impl From<Uint64Limits> for u64 {
145 fn from(val: Uint64Limits) -> Self {
146 val as Self
147 }
148}
149
150#[repr(i8)]
151#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
152pub enum Int8Limits {
153 Min = -0x80,
154 Max = 0x7f,
155}
156
157impl Int8Limits {
158 pub fn from_raw(raw: i8) -> Option<Self> {
159 match raw {
160 -0x80 => Some(Self::Min),
161
162 0x7f => Some(Self::Max),
163
164 _ => None,
165 }
166 }
167}
168
169impl From<Int8Limits> for i8 {
170 fn from(val: Int8Limits) -> Self {
171 val as Self
172 }
173}
174
175#[repr(i16)]
176#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
177pub enum Int16Limits {
178 Min = -0x8000,
179 Max = 0x7fff,
180}
181
182impl Int16Limits {
183 pub fn from_raw(raw: i16) -> Option<Self> {
184 match raw {
185 -0x8000 => Some(Self::Min),
186
187 0x7fff => Some(Self::Max),
188
189 _ => None,
190 }
191 }
192}
193
194impl From<Int16Limits> for i16 {
195 fn from(val: Int16Limits) -> Self {
196 val as Self
197 }
198}
199
200#[repr(i32)]
201#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
202pub enum Int32Limits {
203 Min = -0x80000000,
204 Max = 0x7fffffff,
205}
206
207impl Int32Limits {
208 pub fn from_raw(raw: i32) -> Option<Self> {
209 match raw {
210 -0x80000000 => Some(Self::Min),
211
212 0x7fffffff => Some(Self::Max),
213
214 _ => None,
215 }
216 }
217}
218
219impl From<Int32Limits> for i32 {
220 fn from(val: Int32Limits) -> Self {
221 val as Self
222 }
223}
224
225#[repr(i64)]
226#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
227pub enum Int64Limits {
228 Min = -0x8000000000000000,
229 Max = 0x7fffffffffffffff,
230}
231
232impl Int64Limits {
233 pub fn from_raw(raw: i64) -> Option<Self> {
234 match raw {
235 -0x8000000000000000 => Some(Self::Min),
236
237 0x7fffffffffffffff => Some(Self::Max),
238
239 _ => None,
240 }
241 }
242}
243
244impl From<Int64Limits> for i64 {
245 fn from(val: Int64Limits) -> Self {
246 val as Self
247 }
248}
249
250pub const FOUR: u16 = 0b100;
251
252#[repr(u16)]
253#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
254pub enum EnumWithExpressions {
255 OrWithLiteral = 3, OrWithConstant = 5, }
258
259impl EnumWithExpressions {
260 pub fn from_raw(raw: u16) -> Option<Self> {
261 match raw {
262 3 => Some(Self::OrWithLiteral),
263
264 5 => Some(Self::OrWithConstant),
265
266 _ => None,
267 }
268 }
269}
270
271impl From<EnumWithExpressions> for u16 {
272 fn from(val: EnumWithExpressions) -> Self {
273 val as Self
274 }
275}
276
277#[repr(u8)]
279#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
280pub enum EnumWithOneLineComment {
281 MemberWithOneLineComment = 0,
283
284 MemberWithManyLineComment = 1,
289}
290
291impl EnumWithOneLineComment {
292 pub fn from_raw(raw: u8) -> Option<Self> {
293 match raw {
294 0 => Some(Self::MemberWithOneLineComment),
295
296 1 => Some(Self::MemberWithManyLineComment),
297
298 _ => None,
299 }
300 }
301}
302
303impl From<EnumWithOneLineComment> for u8 {
304 fn from(val: EnumWithOneLineComment) -> Self {
305 val as Self
306 }
307}
308
309#[repr(u16)]
315#[derive(Clone, Copy, Debug, Eq, Hash, IntoBytes, PartialEq, TryFromBytes)]
316pub enum EnumWithManyLineComment {
317 Member = 0,
318}
319
320impl EnumWithManyLineComment {
321 pub fn from_raw(raw: u16) -> Option<Self> {
322 match raw {
323 0 => Some(Self::Member),
324
325 _ => None,
326 }
327 }
328}
329
330impl From<EnumWithManyLineComment> for u16 {
331 fn from(val: EnumWithManyLineComment) -> Self {
332 val as Self
333 }
334}
335
336pub const RED: Color = Color::Red;
337
338pub const UINT8_MIN: Uint8Limits = Uint8Limits::Min;
339
340pub const UINT8_MAX: Uint8Limits = Uint8Limits::Max;
341
342pub const UINT16_MIN: Uint16Limits = Uint16Limits::Min;
343
344pub const UINT16_MAX: Uint16Limits = Uint16Limits::Max;
345
346pub const UINT32_MIN: Uint32Limits = Uint32Limits::Min;
347
348pub const UINT32_MAX: Uint32Limits = Uint32Limits::Max;
349
350pub const UINT64_MIN: Uint64Limits = Uint64Limits::Min;
351
352pub const UINT64_MAX: Uint64Limits = Uint64Limits::Max;
353
354pub const INT8_MIN: Int8Limits = Int8Limits::Min;
355
356pub const INT8_MAX: Int8Limits = Int8Limits::Max;
357
358pub const INT16_MIN: Int16Limits = Int16Limits::Min;
359
360pub const INT16_MAX: Int16Limits = Int16Limits::Max;
361
362pub const INT32_MIN: Int32Limits = Int32Limits::Min;
363
364pub const INT32_MAX: Int32Limits = Int32Limits::Max;
365
366pub const INT64_MIN: Int64Limits = Int64Limits::Min;
367
368pub const INT64_MAX: Int64Limits = Int64Limits::Max;