pub fn gen_struct_with_rename(
typ: &TypeDef,
mapper: &dyn TypeMapper,
cfg: &RustBindingConfig<'_>,
extra_field_attrs: impl Fn(&FieldDef) -> Vec<String>,
field_name_override: impl Fn(&FieldDef) -> Option<String>,
) -> StringExpand description
Generate a struct definition using the builder, with per-field attribute and name override callbacks.
This is the most flexible variant. Use it when the target language may need to escape
reserved keywords in field names (e.g. Python’s class → class_).
extra_field_attrs— called per field, returns additional#[…]attribute strings to append aftercfg.field_attrs. Return an empty vec for the default behaviour.field_name_override— called per field, returnsSome(escaped_name)when the Rust binding struct field name should differ fromfield.name(e.g. for keyword escaping), orNoneto keep the original name.
When a field name is overridden the caller is responsible for adding the appropriate
language attribute (e.g. pyo3(get, name = "original")) via extra_field_attrs.
cfg.field_attrs is still applied for non-renamed fields; for renamed fields the
caller should replace the default field attrs entirely by returning them from
extra_field_attrs and passing a modified cfg with empty field_attrs.