@@ -2,7 +2,8 @@ use bindgen::callbacks::TypeKind;
2
2
use bindgen:: {
3
3
builder, Abi , AliasVariation , Builder , CodegenConfig , EnumVariation ,
4
4
FieldVisibilityKind , Formatter , MacroTypeVariation , NonCopyUnionStyle ,
5
- RegexSet , RustTarget , DEFAULT_ANON_FIELDS_PREFIX , RUST_TARGET_STRINGS ,
5
+ RegexSet , RustEnumOptions , RustTarget , DEFAULT_ANON_FIELDS_PREFIX ,
6
+ RUST_TARGET_STRINGS ,
6
7
} ;
7
8
use clap:: error:: { Error , ErrorKind } ;
8
9
use clap:: { CommandFactory , Parser } ;
@@ -75,6 +76,21 @@ fn parse_abi_override(abi_override: &str) -> Result<(Abi, String), Error> {
75
76
Ok ( ( abi, regex. to_owned ( ) ) )
76
77
}
77
78
79
+ fn parse_rustified_enum (
80
+ rustified_enum : & str ,
81
+ ) -> Result < ( RustEnumOptions , String ) , Error > {
82
+ let ( regex, options) = match rustified_enum. rsplit_once ( '=' ) {
83
+ Some ( ( regex, options) ) => ( regex, options) ,
84
+ None => ( rustified_enum, "" ) ,
85
+ } ;
86
+
87
+ let options = options
88
+ . parse ( )
89
+ . map_err ( |err| Error :: raw ( ErrorKind :: InvalidValue , err) ) ?;
90
+
91
+ Ok ( ( options, regex. to_owned ( ) ) )
92
+ }
93
+
78
94
fn parse_custom_derive (
79
95
custom_derive : & str ,
80
96
) -> Result < ( Vec < String > , String ) , Error > {
@@ -111,12 +127,11 @@ struct BindgenCommand {
111
127
/// Mark any enum whose name matches REGEX as a global newtype.
112
128
#[ arg( long, value_name = "REGEX" ) ]
113
129
newtype_global_enum : Vec < String > ,
114
- /// Mark any enum whose name matches REGEX as a Rust enum.
115
- #[ arg( long, value_name = "REGEX" ) ]
116
- rustified_enum : Vec < String > ,
117
- /// Mark any enum whose name matches REGEX as a non-exhaustive Rust enum.
118
- #[ arg( long, value_name = "REGEX" ) ]
119
- rustified_non_exhaustive_enum : Vec < String > ,
130
+ /// Mark any enum whose name matches the provided regex as a Rust enum. This parameter takes
131
+ /// options in the shape REGEX or REGEX=OPTIONS where OPTIONS can be a comma separated list of
132
+ /// options from non_exhaustive, try_from_raw, and from_raw_unchecked.
133
+ #[ arg( long, value_parser = parse_rustified_enum) ]
134
+ rustified_enum : Vec < ( RustEnumOptions , String ) > ,
120
135
/// Mark any enum whose name matches REGEX as a series of constants.
121
136
#[ arg( long, value_name = "REGEX" ) ]
122
137
constified_enum : Vec < String > ,
@@ -472,7 +487,6 @@ where
472
487
newtype_enum,
473
488
newtype_global_enum,
474
489
rustified_enum,
475
- rustified_non_exhaustive_enum,
476
490
constified_enum,
477
491
constified_enum_module,
478
492
default_macro_constant_type,
@@ -635,12 +649,8 @@ where
635
649
builder = builder. newtype_global_enum ( regex) ;
636
650
}
637
651
638
- for regex in rustified_enum {
639
- builder = builder. rustified_enum ( regex) ;
640
- }
641
-
642
- for regex in rustified_non_exhaustive_enum {
643
- builder = builder. rustified_non_exhaustive_enum ( regex) ;
652
+ for ( options, regex) in rustified_enum {
653
+ builder = builder. rustified_enum ( options, regex) ;
644
654
}
645
655
646
656
for regex in constified_enum {
0 commit comments