@@ -223,10 +223,24 @@ macro_rules! e {
223
223
///
224
224
/// See <https://github.com/rust-lang/libc/issues/4419> for more.
225
225
macro_rules! c_enum {
226
- (
226
+ ( $(
227
+ $( #[ repr( $repr: ty) ] ) ?
228
+ pub enum $ty_name: ident {
229
+ $( $variant: ident $( = $value: expr) ?, ) +
230
+ }
231
+ ) +) => {
232
+ $( c_enum!( @expand;
233
+ $( #[ repr( $repr) ] ) ?
234
+ pub enum $ty_name {
235
+ $( $variant $( = $value) ?, ) +
236
+ }
237
+ ) ; ) +
238
+ } ;
239
+
240
+ ( @expand;
227
241
$( #[ repr( $repr: ty) ] ) ?
228
- enum $ty_name: ident {
229
- $( $variant: ident $( = $value: literal ) ?, ) +
242
+ pub enum $ty_name: ident {
243
+ $( $variant: ident $( = $value: expr ) ?, ) +
230
244
}
231
245
) => {
232
246
pub type $ty_name = c_enum!( @ty $( $repr) ?) ;
@@ -237,7 +251,7 @@ macro_rules! c_enum {
237
251
( @one; $_ty_name: ident; $_idx: expr; ) => { } ;
238
252
(
239
253
@one; $ty_name: ident; $default_val: expr;
240
- $variant: ident $( = $value: literal ) ?,
254
+ $variant: ident $( = $value: expr ) ?,
241
255
$( $tail: tt) *
242
256
) => {
243
257
pub const $variant: $ty_name = {
@@ -413,7 +427,7 @@ mod tests {
413
427
fn c_enumbasic ( ) {
414
428
// By default, variants get sequential values.
415
429
c_enum ! {
416
- enum e {
430
+ pub enum e {
417
431
VAR0 ,
418
432
VAR1 ,
419
433
VAR2 ,
@@ -430,7 +444,7 @@ mod tests {
430
444
// By default, variants get sequential values.
431
445
c_enum ! {
432
446
#[ repr( u16 ) ]
433
- enum e {
447
+ pub enum e {
434
448
VAR0 ,
435
449
}
436
450
}
@@ -442,7 +456,7 @@ mod tests {
442
456
fn c_enumset_value ( ) {
443
457
// Setting an explicit value resets the count.
444
458
c_enum ! {
445
- enum e {
459
+ pub enum e {
446
460
VAR2 = 2 ,
447
461
VAR3 ,
448
462
VAR4 ,
@@ -459,7 +473,7 @@ mod tests {
459
473
// C enums always take one more than the previous value, unless set to a specific
460
474
// value. Duplicates are allowed.
461
475
c_enum ! {
462
- enum e {
476
+ pub enum e {
463
477
VAR0 ,
464
478
VAR2_0 = 2 ,
465
479
VAR3_0 ,
0 commit comments