1
- use core:: { fmt, num:: NonZeroU32 } ;
1
+ use core:: {
2
+ fmt,
3
+ num:: { NonZeroU32 , NonZeroU8 } ,
4
+ } ;
2
5
3
6
macro_rules! pseudo_enum {
4
- ( $( #[ $attr: meta] ) * $name: ident { $( $case: ident = $value: literal, ) * } ) => {
7
+ ( $( #[ $attr: meta] ) * $container : ident ( $prim : ident ) $ name: ident { $( $case: ident = $value: literal, ) * } ) => {
5
8
$( #[ $attr] ) *
6
9
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
7
- pub struct $name( pub NonZeroU32 ) ;
10
+ pub struct $name( $container) ;
11
+
8
12
#[ allow( non_upper_case_globals) ]
9
13
impl $name {
10
- pub fn new( x: u32 ) -> Option <Self > {
11
- Some ( Self ( NonZeroU32 :: new( x) ?) )
14
+ pub fn new( x: $prim) -> Option <Self > {
15
+ Some ( Self ( $container:: new( x) ?) )
16
+ }
17
+
18
+ pub fn value( & self ) -> $prim {
19
+ self . 0 . get( )
12
20
}
13
21
14
22
$(
15
- pub const $case: Self = Self ( unsafe { NonZeroU32 :: new_unchecked( $value) } ) ;
23
+ pub const $case: Self = Self ( unsafe { $container :: new_unchecked( $value) } ) ;
16
24
) *
17
25
}
18
26
@@ -33,7 +41,7 @@ macro_rules! pseudo_enum {
33
41
34
42
pseudo_enum ! {
35
43
/// Known texture formats
36
- Format {
44
+ NonZeroU32 ( u32 ) Format {
37
45
R4G4_UNORM_PACK8 = 1 ,
38
46
R4G4B4A4_UNORM_PACK16 = 2 ,
39
47
B4G4R4A4_UNORM_PACK16 = 3 ,
@@ -206,15 +214,15 @@ pseudo_enum! {
206
214
207
215
pseudo_enum ! {
208
216
/// Known supercompression schemes
209
- SupercompressionScheme {
217
+ NonZeroU32 ( u32 ) SupercompressionScheme {
210
218
BasisLZ = 1 ,
211
219
Zstandard = 2 ,
212
220
ZLIB = 3 ,
213
221
}
214
222
}
215
223
216
224
pseudo_enum ! {
217
- ColorModel {
225
+ NonZeroU8 ( u8 ) ColorModel {
218
226
RGBSDA = 1 ,
219
227
YUVSDA = 2 ,
220
228
YIQSDA = 3 ,
@@ -248,7 +256,7 @@ pseudo_enum! {
248
256
}
249
257
250
258
pseudo_enum ! {
251
- ColorPrimaries {
259
+ NonZeroU8 ( u8 ) ColorPrimaries {
252
260
BT709 = 1 ,
253
261
BT601EBU = 2 ,
254
262
BT601SMPTE = 3 ,
@@ -264,7 +272,7 @@ pseudo_enum! {
264
272
}
265
273
266
274
pseudo_enum ! {
267
- TransferFunction {
275
+ NonZeroU8 ( u8 ) TransferFunction {
268
276
Linear = 1 ,
269
277
SRGB = 2 ,
270
278
ITU = 3 ,
0 commit comments