Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.8k stars 152 forks source link

Add `attributes` to `strum_discriminants` for custom attributes in generated discriminant enum #320

Open 0x5abe opened 11 months ago

0x5abe commented 11 months ago

Sometimes derive macros need a specific attribute to be above them to work properly. I ran across this while using bilge, where the TryFromBits derive macro requires the bitsize attribute above it. The EnumDiscriminants derive macro currently doesn't allow for arbitrary attribute macros before the generated enum's derives, so I added the #[strum_discriminants(attributes(..))] attribute to allow for this.

This PR is a draft because I am not entirely sure how a test for this specific attribute would be performed, and I wouldn't want it to get merged without its proper tests.

Peternator7 commented 9 months ago

Hey @SabeMP, I'd suggest the following. If we can find an example with serde where this would be helpful, I'd be happy to add that as a dependency to the tests crate so we can validate this works consistently.

Also, could you undo the formatting changes?