Commit Graph

1 Commits (master)

Author SHA1 Message Date
Filipe Xavier 0e62e4f3e5 rust: add `impl_flags!` macro for defining common bitflag operations
We have seen a proliferation of `mod_whatever::foo::Flags` being
defined with essentially the same implementation for `BitAnd`, `BitOr`,
`.contains()` 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@collabora.com>
Suggested-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
Link: https://patch.msgid.link/20260117-feat-add-bitmask-macro-v9-1-45ea1f00f846@gmail.com
[ 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 ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2026-02-02 08:09:11 +01:00