in src/bindgen/ir/union.rs [165:213]
fn rename_for_config(&mut self, config: &Config) {
config.export.rename(&mut self.export_name);
for field in &mut self.fields {
field.ty.rename_for_config(config, &self.generic_params);
}
let rules = self.annotations.parse_atom::<RenameRule>("rename-all");
let rules = rules.as_ref().unwrap_or(&config.structure.rename_fields);
if let Some(o) = self.annotations.list("field-names") {
let mut overriden_fields = Vec::new();
for (i, field) in self.fields.iter().enumerate() {
if i >= o.len() {
overriden_fields.push(field.clone());
} else {
overriden_fields.push(Field {
name: o[i].clone(),
ty: field.ty.clone(),
cfg: field.cfg.clone(),
annotations: field.annotations.clone(),
documentation: field.documentation.clone(),
});
}
}
self.fields = overriden_fields;
} else if let Some(r) = rules.not_none() {
self.fields = self
.fields
.iter()
.map(|field| Field {
name: r
.apply(&field.name, IdentifierType::StructMember)
.into_owned(),
ty: field.ty.clone(),
cfg: field.cfg.clone(),
annotations: field.annotations.clone(),
documentation: field.documentation.clone(),
})
.collect();
} else if self.tuple_union {
// If we don't have any rules for a tuple union, prefix them with
// an underscore so it still compiles
for field in &mut self.fields {
field.name.insert(0, '_');
}
}
}