1#[cfg_attr(
3 feature = "serde",
4 derive(serde::Deserialize, serde::Serialize),
5 serde(rename_all = "snake_case")
6)]
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum DataType {
9 U8,
11 U16,
13 U32,
15 U64,
17 I8,
19 I16,
21 I32,
23 I64,
25 U8Ptr,
27 U16Ptr,
29 U32Ptr,
31 U64Ptr,
33 I8Ptr,
35 I16Ptr,
37 I32Ptr,
39 I64Ptr,
41}
42
43impl DataType {
44 pub fn parse_str(s: &str) -> Option<Self> {
46 match s {
47 "uint8_t" => Some(Self::U8),
48 "uint16_t" => Some(Self::U16),
49 "uint32_t" => Some(Self::U32),
50 "uint64_t" => Some(Self::U64),
51 "int8_t" => Some(Self::I8),
52 "int16_t" => Some(Self::I16),
53 "int32_t" => Some(Self::I32),
54 "int64_t" => Some(Self::I64),
55 "uint8_t *" => Some(Self::U8Ptr),
56 "uint16_t *" => Some(Self::U16Ptr),
57 "uint32_t *" => Some(Self::U32Ptr),
58 "uint64_t *" => Some(Self::U64Ptr),
59 "int8_t *" => Some(Self::I8Ptr),
60 "int16_t *" => Some(Self::I16Ptr),
61 "int32_t *" => Some(Self::I32Ptr),
62 "int64_t *" => Some(Self::I64Ptr),
63 _ => None,
64 }
65 }
66
67 pub const fn as_str(self) -> &'static str {
69 match self {
70 Self::U8 => "uint8_t",
71 Self::U16 => "uint16_t",
72 Self::U32 => "uint32_t",
73 Self::U64 => "uint64_t",
74 Self::I8 => "int8_t",
75 Self::I16 => "int16_t",
76 Self::I32 => "int32_t",
77 Self::I64 => "int64_t",
78 Self::U8Ptr => "uint8_t *",
79 Self::U16Ptr => "uint16_t *",
80 Self::U32Ptr => "uint32_t *",
81 Self::U64Ptr => "uint64_t *",
82 Self::I8Ptr => "int8_t *",
83 Self::I16Ptr => "int16_t *",
84 Self::I32Ptr => "int32_t *",
85 Self::I64Ptr => "int64_t *",
86 }
87 }
88}