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 13, 2022
1 parent 20ddfff commit 7bd8084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/bindgen/config.rs
Expand Up @@ -559,6 +559,9 @@ 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 union body members.
/// Applied before rename_variants rename rule. Defaults to SnakeCase.
pub rename_union_body_members: 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 +603,7 @@ impl Default for EnumConfig {
fn default() -> EnumConfig {
EnumConfig {
rename_variants: RenameRule::None,
rename_union_body_members: 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_union_body_members;
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 7bd8084

Please sign in to comment.