@@ -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 } ;
@@ -77,6 +78,21 @@ fn parse_abi_override(abi_override: &str) -> Result<(Abi, String), Error> {
77
78
Ok ( ( abi, regex. to_owned ( ) ) )
78
79
}
79
80
81
+ fn parse_rustified_enum (
82
+ rustified_enum : & str ,
83
+ ) -> Result < ( RustEnumOptions , String ) , Error > {
84
+ let ( regex, options) = match rustified_enum. rsplit_once ( '=' ) {
85
+ Some ( ( regex, options) ) => ( regex, options) ,
86
+ None => ( rustified_enum, "" ) ,
87
+ } ;
88
+
89
+ let options = options
90
+ . parse ( )
91
+ . map_err ( |err| Error :: raw ( ErrorKind :: InvalidValue , err) ) ?;
92
+
93
+ Ok ( ( options, regex. to_owned ( ) ) )
94
+ }
95
+
80
96
fn parse_custom_derive (
81
97
custom_derive : & str ,
82
98
) -> Result < ( Vec < String > , String ) , Error > {
@@ -150,12 +166,11 @@ struct BindgenCommand {
150
166
/// Mark any enum whose name matches REGEX as a global newtype.
151
167
#[ arg( long, value_name = "REGEX" ) ]
152
168
newtype_global_enum : Vec < String > ,
153
- /// Mark any enum whose name matches REGEX as a Rust enum.
154
- #[ arg( long, value_name = "REGEX" ) ]
155
- rustified_enum : Vec < String > ,
156
- /// Mark any enum whose name matches REGEX as a non-exhaustive Rust enum.
157
- #[ arg( long, value_name = "REGEX" ) ]
158
- rustified_non_exhaustive_enum : Vec < String > ,
169
+ /// Mark any enum whose name matches the provided regex as a Rust enum. This parameter takes
170
+ /// options in the shape REGEX or REGEX=OPTIONS where OPTIONS can be a comma separated list of
171
+ /// options from non_exhaustive, try_from_raw, and from_raw_unchecked.
172
+ #[ arg( long, value_parser = parse_rustified_enum) ]
173
+ rustified_enum : Vec < ( RustEnumOptions , String ) > ,
159
174
/// Mark any enum whose name matches REGEX as a series of constants.
160
175
#[ arg( long, value_name = "REGEX" ) ]
161
176
constified_enum : Vec < String > ,
@@ -523,7 +538,6 @@ where
523
538
newtype_enum,
524
539
newtype_global_enum,
525
540
rustified_enum,
526
- rustified_non_exhaustive_enum,
527
541
constified_enum,
528
542
constified_enum_module,
529
543
default_macro_constant_type,
@@ -690,12 +704,8 @@ where
690
704
builder = builder. newtype_global_enum ( regex) ;
691
705
}
692
706
693
- for regex in rustified_enum {
694
- builder = builder. rustified_enum ( regex) ;
695
- }
696
-
697
- for regex in rustified_non_exhaustive_enum {
698
- builder = builder. rustified_non_exhaustive_enum ( regex) ;
707
+ for ( options, regex) in rustified_enum {
708
+ builder = builder. rustified_enum ( options, regex) ;
699
709
}
700
710
701
711
for regex in constified_enum {
0 commit comments