Skip to content

Commit

Permalink
Support rename rule for union body members
Browse files Browse the repository at this point in the history
  • Loading branch information
voorka committed Apr 15, 2022
1 parent 20ddfff commit e3c15ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/bindgen/config.rs
Expand Up @@ -559,6 +559,10 @@ impl StructConfig {
pub struct EnumConfig {
/// The rename rule to apply to the name of enum variants
pub rename_variants: RenameRule,
/// The rename rule to apply to the names of the union fields in C/C++
/// generated from the Rust enum. Applied before rename_variants
/// rename rule. Defaults to SnakeCase.
pub rename_variant_name_fields: RenameRule,
/// Whether to add a `Sentinel` value at the end of every enum
/// This is useful in Gecko for IPC serialization
pub add_sentinel: bool,
Expand Down Expand Up @@ -600,6 +604,7 @@ impl Default for EnumConfig {
fn default() -> EnumConfig {
EnumConfig {
rename_variants: RenameRule::None,
rename_variant_name_fields: RenameRule::SnakeCase,
add_sentinel: false,
prefix_with_name: false,
derive_helper_methods: false,
Expand Down
5 changes: 3 additions & 2 deletions src/bindgen/ir/enumeration.rs
Expand Up @@ -149,11 +149,12 @@ impl EnumVariant {
if let Some(b) = enum_annotations.bool("derive-ostream") {
annotations.add_default("derive-ostream", AnnotationValue::Bool(b));
}
let body_rule = config.enumeration.rename_variant_name_fields;
let body = match variant.fields {
syn::Fields::Unit => VariantBody::Empty(annotations),
syn::Fields::Named(ref fields) => {
let path = Path::new(format!("{}_Body", variant.ident));
let name = RenameRule::SnakeCase
let name = body_rule
.apply(
&variant.ident.unraw().to_string(),
IdentifierType::StructMember,
Expand All @@ -179,7 +180,7 @@ impl EnumVariant {
}
syn::Fields::Unnamed(ref fields) => {
let path = Path::new(format!("{}_Body", variant.ident));
let name = RenameRule::SnakeCase
let name = body_rule
.apply(
&variant.ident.unraw().to_string(),
IdentifierType::StructMember,
Expand Down

0 comments on commit e3c15ff

Please sign in to comment.