rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.5k stars 700 forks source link

Callback for custom attributes #2963

Open cloneable opened 1 month ago

cloneable commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

So, apparently, there's already support for this since 0.70.0, according to the change log: https://github.com/rust-lang/rust-bindgen/blob/07bbd04ea5f386aa3b83e792548127e2a2e33c43/CHANGELOG.md#L240 And the callback method can be found in the main branch: https://github.com/rust-lang/rust-bindgen/blob/07bbd04ea5f386aa3b83e792548127e2a2e33c43/bindgen/callbacks.rs#L132-L138 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.