Add a callback to rename field names#2524
Conversation
|
☔ The latest upstream changes (presumably 4faa366) made this pull request unmergeable. Please resolve the merge conflicts. |
| None | ||
| } | ||
|
|
||
| /// Allows renaming the name of a field, replacing `_name`. |
There was a problem hiding this comment.
Could you specify what parent_name is? Assuming it's the struct type, something like type_name may be better, since usually parent/child refer to nested types or modules (rather than fields).
| let name = ctx.rust_mangle(name); | ||
| ctx.options() | ||
| .process_field_name(&parent_name, &name) | ||
| .map(|name| Cow::Owned(name)) |
There was a problem hiding this comment.
| .map(|name| Cow::Owned(name)) | |
| .map(Cow::Owned) |
| .map(|name| { | ||
| let name = ctx.rust_mangle(name); | ||
| ctx.options() | ||
| .process_field_name(&parent_name, &name) |
There was a problem hiding this comment.
Clippy says
this expression creates a reference which is immediately dereferenced by the compiler
can you remove the &? (not sure which one or both)
| ctx.options() | ||
| .process_field_name(&parent_name, &name) | ||
| .map(|name| Cow::Owned(name)) | ||
| .unwrap_or(name.to_owned()) |
There was a problem hiding this comment.
| .unwrap_or(name.to_owned()) | |
| .unwrap_or(name.into_owned()) |
Per clippy
this
to_ownedcall clones the Cow<', str> itself and does not cause the Cow<', str> contents to become owned
|
☔ The latest upstream changes (possibly #3365) made this pull request unmergeable. Please resolve the merge conflicts. |
I've been using this callback to rename anonymous fields:
Source struct (from https://github.com/GPUOpen-LibrariesAndSDKs/RenderPipelineShaders):
I'm not sure whether this is implemented in the best way. Very happy to make changes.