Skip to content
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

Callback for custom attributes #2963

Open
cloneable opened this issue Oct 27, 2024 · 2 comments
Open

Callback for custom attributes #2963

cloneable opened this issue Oct 27, 2024 · 2 comments

Comments

@cloneable
Copy link

Hi!
I would like to ask if we can add a method to ParseCallback that emits custom attributes? I have a several larger enums generated by bindgen and would like to use strum::EnumString to look up variants by name, but to make it efficient I also want to add #[strum(use_phf)]. The former can be easily done, but the latter doesn't seem possible with bindgen.

Is this something you'd be open to adding to ParseCallback? I could imagine this to be useful for serde, too.

@emilio
Copy link
Contributor

emilio commented Oct 27, 2024

Probably not to ParseCallback, since it's not something that needs done during parsing? But yeah, it seems generalizing the derive API to also support other attributes seems reasonable.

@cloneable
Copy link
Author

So, apparently, there's already support for this since 0.70.0, according to the change log:

- Add support for custom attributes (--with-attribute-custom, #2866)

And the callback method can be found in the main branch:
/// Provide a list of custom attributes.
///
/// If no additional attributes are wanted, this function should return an
/// empty `Vec`.
fn add_attributes(&self, _info: &AttributeInfo<'_>) -> Vec<String> {
vec![]
}

But is not part of tagged version 0.70.0 and .1. That's why I couldn't find it.

Ok, I guess I will just wait for 0.71 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants