Add `union_fields_prefix` option
Signed-off-by: Varphone Wong <varphone@qq.com>
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index 56479da..3a8254a 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -828,8 +828,11 @@
}
anon_field_counter += 1;
+ let default_prefix = "__bindgen_anon_".to_string();
+ let prefix =
+ ctx.options().union_fields_prefix.as_ref().unwrap_or(&default_prefix);
let generated_name =
- format!("__bindgen_anon_{}", anon_field_counter);
+ format!("{}{}", prefix, anon_field_counter);
*name = Some(generated_name);
}
Field::Bitfields(ref mut bu) => {
diff --git a/src/lib.rs b/src/lib.rs
index f5c58cd..0c6319b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -453,6 +453,11 @@
output_vector.push(prefix.clone());
}
+ if let Some(ref prefix) = self.options.union_fields_prefix {
+ output_vector.push("--union-fields-prefix".into());
+ output_vector.push(prefix.clone());
+ }
+
if self.options.emit_ast {
output_vector.push("--emit-clang-ast".into());
}
@@ -1325,6 +1330,12 @@
self
}
+ /// Set prefix of the union type fields name.
+ pub fn union_fields_prefix<T: Into<String>>(mut self, prefix: T) -> Builder {
+ self.options.union_fields_prefix = Some(prefix.into());
+ self
+ }
+
/// Allows configuring types in different situations, see the
/// [`ParseCallbacks`](./callbacks/trait.ParseCallbacks.html) documentation.
pub fn parse_callbacks(
@@ -1693,6 +1704,9 @@
/// An optional prefix for the "raw" types, like `c_int`, `c_void`...
ctypes_prefix: Option<String>,
+ /// The prefix of the union fields name.
+ union_fields_prefix: Option<String>,
+
/// Whether to time the bindgen phases.
time_phases: bool,
@@ -1907,6 +1921,7 @@
disable_nested_struct_naming: false,
use_core: false,
ctypes_prefix: None,
+ union_fields_prefix: None,
namespaced_constants: true,
msvc_mangling: false,
convert_floats: true,
diff --git a/src/options.rs b/src/options.rs
index b630bb4..7196e0c 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -234,6 +234,14 @@
)
.value_name("prefix")
.takes_value(true),
+ Arg::with_name("union-fields-prefix")
+ .long("union-fields-prefix")
+ .help(
+ "Use the given prefix for union fields name instead of \
+ __bindgen_anon_.",
+ )
+ .value_name("prefix")
+ .takes_value(true),
Arg::with_name("time-phases")
.long("time-phases")
.help("Time the different bindgen phases and print to stderr"),