fidl_data_zither_enums/
enums.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// DO NOT EDIT.
6// Generated from FIDL library `zither.enums` by zither, a Fuchsia platform tool.
7
8#![allow(unused_imports)]
9
10use zerocopy::IntoBytes;
11
12#[repr(u8)]
13#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
14pub enum Color {
15    Red = 0,
16    Orange = 1,
17    Yellow = 2,
18    Green = 3,
19    Blue = 4,
20    Indigo = 5,
21    Violet = 6,
22}
23
24impl Color {
25    pub fn from_raw(raw: u8) -> Option<Self> {
26        match raw {
27            0 => Some(Self::Red),
28
29            1 => Some(Self::Orange),
30
31            2 => Some(Self::Yellow),
32
33            3 => Some(Self::Green),
34
35            4 => Some(Self::Blue),
36
37            5 => Some(Self::Indigo),
38
39            6 => Some(Self::Violet),
40
41            _ => None,
42        }
43    }
44}
45
46#[repr(u8)]
47#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
48pub enum Uint8Limits {
49    Min = 0,
50    Max = 0b11111111,
51}
52
53impl Uint8Limits {
54    pub fn from_raw(raw: u8) -> Option<Self> {
55        match raw {
56            0 => Some(Self::Min),
57
58            0b11111111 => Some(Self::Max),
59
60            _ => None,
61        }
62    }
63}
64
65#[repr(u16)]
66#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
67pub enum Uint16Limits {
68    Min = 0,
69    Max = 0xffff,
70}
71
72impl Uint16Limits {
73    pub fn from_raw(raw: u16) -> Option<Self> {
74        match raw {
75            0 => Some(Self::Min),
76
77            0xffff => Some(Self::Max),
78
79            _ => None,
80        }
81    }
82}
83
84#[repr(u32)]
85#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
86pub enum Uint32Limits {
87    Min = 0,
88    Max = 0xffffffff,
89}
90
91impl Uint32Limits {
92    pub fn from_raw(raw: u32) -> Option<Self> {
93        match raw {
94            0 => Some(Self::Min),
95
96            0xffffffff => Some(Self::Max),
97
98            _ => None,
99        }
100    }
101}
102
103#[repr(u64)]
104#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
105pub enum Uint64Limits {
106    Min = 0,
107    Max = 0xffffffffffffffff,
108}
109
110impl Uint64Limits {
111    pub fn from_raw(raw: u64) -> Option<Self> {
112        match raw {
113            0 => Some(Self::Min),
114
115            0xffffffffffffffff => Some(Self::Max),
116
117            _ => None,
118        }
119    }
120}
121
122#[repr(i8)]
123#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
124pub enum Int8Limits {
125    Min = -0x80,
126    Max = 0x7f,
127}
128
129impl Int8Limits {
130    pub fn from_raw(raw: i8) -> Option<Self> {
131        match raw {
132            -0x80 => Some(Self::Min),
133
134            0x7f => Some(Self::Max),
135
136            _ => None,
137        }
138    }
139}
140
141#[repr(i16)]
142#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
143pub enum Int16Limits {
144    Min = -0x8000,
145    Max = 0x7fff,
146}
147
148impl Int16Limits {
149    pub fn from_raw(raw: i16) -> Option<Self> {
150        match raw {
151            -0x8000 => Some(Self::Min),
152
153            0x7fff => Some(Self::Max),
154
155            _ => None,
156        }
157    }
158}
159
160#[repr(i32)]
161#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
162pub enum Int32Limits {
163    Min = -0x80000000,
164    Max = 0x7fffffff,
165}
166
167impl Int32Limits {
168    pub fn from_raw(raw: i32) -> Option<Self> {
169        match raw {
170            -0x80000000 => Some(Self::Min),
171
172            0x7fffffff => Some(Self::Max),
173
174            _ => None,
175        }
176    }
177}
178
179#[repr(i64)]
180#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
181pub enum Int64Limits {
182    Min = -0x8000000000000000,
183    Max = 0x7fffffffffffffff,
184}
185
186impl Int64Limits {
187    pub fn from_raw(raw: i64) -> Option<Self> {
188        match raw {
189            -0x8000000000000000 => Some(Self::Min),
190
191            0x7fffffffffffffff => Some(Self::Max),
192
193            _ => None,
194        }
195    }
196}
197
198pub const FOUR: u16 = 0b100;
199
200#[repr(u16)]
201#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
202pub enum EnumWithExpressions {
203    OrWithLiteral = 3,  // 0b01 | 0b10
204    OrWithConstant = 5, // 0b001 | FOUR
205}
206
207impl EnumWithExpressions {
208    pub fn from_raw(raw: u16) -> Option<Self> {
209        match raw {
210            3 => Some(Self::OrWithLiteral),
211
212            5 => Some(Self::OrWithConstant),
213
214            _ => None,
215        }
216    }
217}
218
219/// Enum with a one-line comment.
220#[repr(u8)]
221#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
222pub enum EnumWithOneLineComment {
223    /// Enum member with one-line comment.
224    MemberWithOneLineComment = 0,
225
226    /// Enum member
227    ///     with a
228    ///         many-line
229    ///           comment.
230    MemberWithManyLineComment = 1,
231}
232
233impl EnumWithOneLineComment {
234    pub fn from_raw(raw: u8) -> Option<Self> {
235        match raw {
236            0 => Some(Self::MemberWithOneLineComment),
237
238            1 => Some(Self::MemberWithManyLineComment),
239
240            _ => None,
241        }
242    }
243}
244
245/// Enum
246///
247///     with a
248///         many-line
249///           comment.
250#[repr(u16)]
251#[derive(Clone, Copy, Debug, Eq, IntoBytes, PartialEq)]
252pub enum EnumWithManyLineComment {
253    Member = 0,
254}
255
256impl EnumWithManyLineComment {
257    pub fn from_raw(raw: u16) -> Option<Self> {
258        match raw {
259            0 => Some(Self::Member),
260
261            _ => None,
262        }
263    }
264}
265
266pub const RED: Color = Color::Red;
267
268pub const UINT8_MIN: Uint8Limits = Uint8Limits::Min;
269
270pub const UINT8_MAX: Uint8Limits = Uint8Limits::Max;
271
272pub const UINT16_MIN: Uint16Limits = Uint16Limits::Min;
273
274pub const UINT16_MAX: Uint16Limits = Uint16Limits::Max;
275
276pub const UINT32_MIN: Uint32Limits = Uint32Limits::Min;
277
278pub const UINT32_MAX: Uint32Limits = Uint32Limits::Max;
279
280pub const UINT64_MIN: Uint64Limits = Uint64Limits::Min;
281
282pub const UINT64_MAX: Uint64Limits = Uint64Limits::Max;
283
284pub const INT8_MIN: Int8Limits = Int8Limits::Min;
285
286pub const INT8_MAX: Int8Limits = Int8Limits::Max;
287
288pub const INT16_MIN: Int16Limits = Int16Limits::Min;
289
290pub const INT16_MAX: Int16Limits = Int16Limits::Max;
291
292pub const INT32_MIN: Int32Limits = Int32Limits::Min;
293
294pub const INT32_MAX: Int32Limits = Int32Limits::Max;
295
296pub const INT64_MIN: Int64Limits = Int64Limits::Min;
297
298pub const INT64_MAX: Int64Limits = Int64Limits::Max;