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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// TODO!
use ;
// #[derive(Const)]
// #[armtype(u8)]
// enum TestU8 {
// #[value = 0x7f]
// Arm1,
// #[value = 0x3B]
// Arm2,
// }
// #[derive(Const)]
// #[armtype(&[u8])]
// enum TestU8Slice4 {
// #[value = b"\x7F\x7F\x7F\x7F\x67"]
// Arm1(u8, u8, u8, u8),
// #[value = b"\x3B\x3B\x3B\x3B"]
// Arm2,
// }
// #[derive(Const)]
// #[arm_type(Vec<usize>)]
// enum TestVecu8 {
// #[value = vec![1, 2, 3]]
// Arm1,
// #[value = vec![4, 5, 6]]
// Arm2,
// }
// #[derive(ConstEach)]
// enum TestStrAny {
// #[armtype(u8)]
// #[value = 0xAA]
// Arm1,
// #[value = "test3"]
// Arm2,
// }
// #[derive(ConstEach, Debug)]
// enum MyEnum {
// #[armtype(u8)]
// #[value = 0xAA]
// A,
// #[value = "test3"]
// B,
// }
// #[derive(ConstEach, Debug)]
// enum Tags {
// #[value = b"\x00\x01"]
// Key,
// #[armtype(u16)]
// #[value = 24250]
// Length,
// #[armtype(&[u8])]
// #[value = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"]
// Data,
// }
// fn main2() {
// // [`ConstEach`] examples
// assert!(MyEnum::A.value::<u8>().is_some());
// assert!(MyEnum::A.value::<Vec<f32>>().is_none());
// assert!(MyEnum::B.value::<u8>().is_none());
// assert!(MyEnum::B.value::<&str>().is_some());
// // An infered type. This will be as strict as possible,
// // therefore [`&[u8]`] will fail but [`&[u8; 2]`] will succeed
// assert!(Tags::Key.value::<&[u8; 2]>().is_some());
// assert!(Tags::Key.value::<&[u8; 5]>().is_none());
// assert!(Tags::Key.value::<&[u8]>().is_none());
// assert!(u16::from_le_bytes(**Tags::Key.value::<&[u8; 2]>().unwrap()) == 0x0100);
// // casting as anything other than the defined / inferred type will
// // fail, since this uses [`downcast_ref`] from [`std::any::Any`]
// assert!(Tags::Length.value::<u16>().is_some());
// assert!(Tags::Length.value::<u32>().is_none());
// assert!(Tags::Length.value::<u64>().is_none());
// // however, can always convert to a different type
// // after value is successfully acquired
// assert!(*Tags::Length.value::<u16>().unwrap() as u32 == 24250);
// }
// use enum_const::Const;
// #[derive(Const)]
// #[armtype(i32)]
// enum MyEnum {
// #[value = 0]
// A,
// #[value = 1]
// B,
// }
// #[derive(Const)]
// #[armtype(&[u8])]
// enum Tags {
// #[value = b"\x00\x01\x7f"]
// Key,
// #[value = b"\xba\x5e"]
// Length,
// #[value = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"]
// Data,
// }
// use enum_const::Const;
/// https://exiftool.org/TagNames/EXIF.html
// #[derive(ConstEach)]
// enum CustomEnum {
// #[armtype(&[u8])]
// #[value = b"\x01\x00"]
// A,
// #[value = "foo"]
// B,
// #[armtype(f32)]
// #[value = 3.14]
// C,
// }
// enum MyEnum2 {
// Variant1,
// Variant2(u8),
// Variant3(String, (f32, i16)),
// }