@@ -83,6 +83,7 @@ use ir::context::{BindgenContext, ItemId};
83
83
use ir:: item:: Item ;
84
84
use parse:: { ClangItemParser , ParseError } ;
85
85
use regex_set:: RegexSet ;
86
+ pub use codegen:: EnumVariation ;
86
87
87
88
use std:: borrow:: Cow ;
88
89
use std:: collections:: HashMap ;
@@ -203,6 +204,16 @@ impl Builder {
203
204
output_vector. push ( "--rust-target" . into ( ) ) ;
204
205
output_vector. push ( self . options . rust_target . into ( ) ) ;
205
206
207
+ if self . options . default_enum_style != Default :: default ( ) {
208
+ output_vector. push ( "--default-enum-variant=" . into ( ) ) ;
209
+ output_vector. push ( match self . options . default_enum_style {
210
+ codegen:: EnumVariation :: Rust => "rust" ,
211
+ codegen:: EnumVariation :: Bitfield => "bitfield" ,
212
+ codegen:: EnumVariation :: Consts => "consts" ,
213
+ codegen:: EnumVariation :: ModuleConsts => "moduleconsts" ,
214
+ } . into ( ) )
215
+ }
216
+
206
217
self . options
207
218
. bitfield_enums
208
219
. get_items ( )
@@ -729,6 +740,11 @@ impl Builder {
729
740
self . whitelist_var ( arg)
730
741
}
731
742
743
+ /// Set the default style of code to generate for enums
744
+ pub fn default_enum_style ( mut self , arg : codegen:: EnumVariation ) -> Builder {
745
+ self . options . default_enum_style = arg;
746
+ self
747
+ }
732
748
733
749
/// Mark the given enum (or set of enums, if using a pattern) as being
734
750
/// bitfield-like. Regular expressions are supported.
@@ -1240,6 +1256,9 @@ struct BindgenOptions {
1240
1256
/// Whitelisted variables. See docs for `whitelisted_types` for more.
1241
1257
whitelisted_vars : RegexSet ,
1242
1258
1259
+ /// The default style of code to generate for enums
1260
+ default_enum_style : codegen:: EnumVariation ,
1261
+
1243
1262
/// The enum patterns to mark an enum as bitfield.
1244
1263
bitfield_enums : RegexSet ,
1245
1264
@@ -1458,6 +1477,7 @@ impl Default for BindgenOptions {
1458
1477
whitelisted_types : Default :: default ( ) ,
1459
1478
whitelisted_functions : Default :: default ( ) ,
1460
1479
whitelisted_vars : Default :: default ( ) ,
1480
+ default_enum_style : Default :: default ( ) ,
1461
1481
bitfield_enums : Default :: default ( ) ,
1462
1482
rustified_enums : Default :: default ( ) ,
1463
1483
constified_enum_modules : Default :: default ( ) ,
0 commit comments