rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

RFE: API for renaming struct fields

Open jgcodes2020 opened this issue 5 months ago • 1 comments

Background

ParseCallbacks::enum_variant_name is already useful for renaming enum variants. I'm using it to ensure that generated bindings fit Rust conventions. However, I'd like to also rename struct fields, and there doesn't seem to be a callback for that.

Proposal

Add fn struct_field_name to ParseCallbacks with the following signature:

fn struct_field_name(
    &self,
    struct_name: Option<&str>,
    original_field_name: &str,
) -> Option<String>

This works in a similar manner to ParseCallbacks::enum_variant_name; if the user chooses to return None, the name isn't changed, but if the user chooses to return Some(string), then the field is renamed to string.

jgcodes2020 avatar Mar 24 '24 13:03 jgcodes2020