Add a custom #[flag_name] attribute #483

Merged
KodrAus merged 7 commits from feat/flag-name into main 2026-05-29 00:14:03 -05:00
KodrAus commented 2026-05-28 20:37:57 -05:00 (Migrated from github.com)

Closes #470

This PR introduces a #[flag_name] attribute you can apply to flags to give them a different name. I've tried to avoid adding these kinds of attributes in the past, but there's no way to get around this one with bitflags, so we support it. It lets you write:

bitflags! {
    pub struct MyFlags: u8 {
        #[flag_name = "a"]
        const A = 1;
    }
}

There isn't any validation done on the flag_name given, so you could pick strange names like _, or a | b or a, etc. I need to add some more test coverage before this is ready.

Closes #470 This PR introduces a `#[flag_name]` attribute you can apply to flags to give them a different name. I've tried to avoid adding these kinds of attributes in the past, but there's no way to get around this one with `bitflags`, so we support it. It lets you write: ```rust bitflags! { pub struct MyFlags: u8 { #[flag_name = "a"] const A = 1; } } ``` There isn't any validation done on the `flag_name` given, so you could pick strange names like `_`, or `a | b` or ` a`, etc. I need to add some more test coverage before this is ready.
KodrAus commented 2026-05-28 21:06:31 -05:00 (Migrated from github.com)

Should add some compile-fail tests for malformed #[flag_name]s

Should add some compile-fail tests for malformed `#[flag_name]`s
Sign in to join this conversation.
No reviewers
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-bitflags/bitflags!483
No description provided.