Skip to content

Commit a90bd84

Browse files
rdelfinpvdrz
authored andcommitted
Added non-exhaustive enums to the CLI
1 parent cf9b02f commit a90bd84

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

bindgen-cli/options.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ struct BindgenCommand {
114114
/// Mark any enum whose name matches REGEX as a Rust enum.
115115
#[arg(long, value_name = "REGEX")]
116116
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>,
117120
/// Mark any enum whose name matches REGEX as a series of constants.
118121
#[arg(long, value_name = "REGEX")]
119122
constified_enum: Vec<String>,
@@ -469,6 +472,7 @@ where
469472
newtype_enum,
470473
newtype_global_enum,
471474
rustified_enum,
475+
rustified_non_exhaustive_enum,
472476
constified_enum,
473477
constified_enum_module,
474478
default_macro_constant_type,
@@ -635,6 +639,10 @@ where
635639
builder = builder.rustified_enum(regex);
636640
}
637641

642+
for regex in rustified_non_exhaustive_enum {
643+
builder = builder.rustified_non_exhaustive_enum(regex);
644+
}
645+
638646
for regex in constified_enum {
639647
builder = builder.constified_enum(regex);
640648
}
@@ -1081,8 +1089,8 @@ where
10811089
&self,
10821090
info: &bindgen::callbacks::DeriveInfo<'_>,
10831091
) -> Vec<String> {
1084-
if self.kind.map(|kind| kind == info.kind).unwrap_or(true) &&
1085-
self.regex_set.matches(info.name)
1092+
if self.kind.map(|kind| kind == info.kind).unwrap_or(true)
1093+
&& self.regex_set.matches(info.name)
10861094
{
10871095
return self.derives.clone();
10881096
}

bindgen/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ pub const DEFAULT_ANON_FIELDS_PREFIX: &str = "__bindgen_anon_";
8787
const DEFAULT_NON_EXTERN_FNS_SUFFIX: &str = "__extern";
8888

8989
fn file_is_cpp(name_file: &str) -> bool {
90-
name_file.ends_with(".hpp") ||
91-
name_file.ends_with(".hxx") ||
92-
name_file.ends_with(".hh") ||
93-
name_file.ends_with(".h++")
90+
name_file.ends_with(".hpp")
91+
|| name_file.ends_with(".hxx")
92+
|| name_file.ends_with(".hh")
93+
|| name_file.ends_with(".h++")
9494
}
9595

9696
fn args_are_cpp(clang_args: &[Box<str>]) -> bool {
@@ -237,6 +237,7 @@ impl std::fmt::Display for Formatter {
237237
/// 2. [`bitfield_enum()`](#method.bitfield_enum)
238238
/// 3. [`newtype_enum()`](#method.newtype_enum)
239239
/// 4. [`rustified_enum()`](#method.rustified_enum)
240+
/// 4. [`rustified_non_exhaustive_enum()`](#method.rustified_non_exhaustive_enum)
240241
///
241242
/// For each C enum, bindgen tries to match the pattern in the following order:
242243
///
@@ -798,8 +799,8 @@ impl Bindings {
798799
return false;
799800
}
800801

801-
if arg.starts_with("-I") ||
802-
arg.starts_with("--include-directory=")
802+
if arg.starts_with("-I")
803+
|| arg.starts_with("--include-directory=")
803804
{
804805
return false;
805806
}
@@ -826,8 +827,8 @@ impl Bindings {
826827
debug!("Found clang: {:?}", clang);
827828

828829
// Whether we are working with C or C++ inputs.
829-
let is_cpp = args_are_cpp(&options.clang_args) ||
830-
options.input_headers.iter().any(|h| file_is_cpp(h));
830+
let is_cpp = args_are_cpp(&options.clang_args)
831+
|| options.input_headers.iter().any(|h| file_is_cpp(h));
831832

832833
let search_paths = if is_cpp {
833834
clang.cpp_search_paths

0 commit comments

Comments
 (0)