Re: [PATCH v9] rust: add new macro for common bitflag operations
From: Miguel Ojeda
Date: Mon Feb 02 2026 - 02:22:22 EST
On Sat, Jan 17, 2026 at 11:41 AM Filipe Xavier <felipeaggger@xxxxxxxxx> wrote:
>
> We have seen a proliferation of mod_whatever::foo::Flags
> being defined with essentially the same implementation
> for BitAnd, BitOr, contains and etc.
>
> This macro aims to bring a solution for this,
> allowing to generate these methods for user-defined structs.
> With some use cases in KMS and upcoming GPU drivers.
>
> Link: https://rust-for-linux.zulipchat.com/#narrow/channel/288089-General/topic/We.20really.20need.20a.20common.20.60Flags.60.20type
> Suggested-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
> Suggested-by: Lyude Paul <lyude@xxxxxxxxxx>
> Reviewed-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
> Reviewed-by: Lyude Paul <lyude@xxxxxxxxxx>
> Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> Signed-off-by: Filipe Xavier <felipeaggger@xxxxxxxxx>
Applied to `rust-next` -- thanks everyone!
[ Implemented missing `BitXorAssign<$flag> for $flags`. Sorted
`impl`s. Removed prelude addition for now -- I asked the team and they
also felt it wasn't needed. We can always add it later on if needed.
Fixed intra-doc link (by removing the sentence since it was superfluous
anyway). Simplified `empty()` title. Reworded commit slightly. Added
docs to enum variants in example to avoid 'missing_docs' lint when used
in actual code. - Miguel ]
I wonder if we should check the values that the passed `enum` has,
e.g. about zero. Anyway, we can discuss that later.
Cheers,
Miguel