Skip to content

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

Draft
0x5abe wants to merge 1 commit into
Peternator7:masterfrom
0x5abe:discriminant-enum-custom-attributes
Draft

Add attributes to strum_discriminants for custom attributes in generated discriminant enum#320
0x5abe wants to merge 1 commit into
Peternator7:masterfrom
0x5abe:discriminant-enum-custom-attributes

Conversation

@0x5abe

@0x5abe 0x5abe commented Dec 23, 2023

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Owner

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?

…attributes before the derives in the discriminant enum
@0x5abe
0x5abe force-pushed the discriminant-enum-custom-attributes branch from 882df24 to 3381b08 Compare August 17, 2026 00:35
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

Successfully merging this pull request may close these issues.

2 participants