Skip to content

Add a custom #[flag_name] attribute#483

Merged
KodrAus merged 7 commits into
mainfrom
feat/flag-name
May 29, 2026
Merged

Add a custom #[flag_name] attribute#483
KodrAus merged 7 commits into
mainfrom
feat/flag-name

Conversation

@KodrAus

@KodrAus KodrAus commented May 29, 2026

Copy link
Copy Markdown
Member

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.

@KodrAus

KodrAus commented May 29, 2026

Copy link
Copy Markdown
Member Author

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

@KodrAus KodrAus merged commit ac91b70 into main May 29, 2026
20 checks passed
@KodrAus KodrAus deleted the feat/flag-name branch May 29, 2026 05:14
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.

Add ability to rename flags.

1 participant