-
Notifications
You must be signed in to change notification settings - Fork 699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a callback to rename field names #2524
base: main
Are you sure you want to change the base?
Conversation
☔ The latest upstream changes (presumably 4faa366) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -135,6 +135,15 @@ pub trait ParseCallbacks: fmt::Debug { | |||
fn process_comment(&self, _comment: &str) -> Option<String> { | |||
None | |||
} | |||
|
|||
/// Allows renaming the name of a field, replacing `_name`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.unwrap_or(name.to_owned()) | |
.unwrap_or(name.into_owned()) |
Per clippy
this
to_owned
call clones the Cow<', str> itself and does not cause the Cow<', str> contents to become owned
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.