[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <FC15901F-F607-40E8-928F-5EA7F364B0CE@collabora.com>
Date: Sun, 8 Feb 2026 10:56:22 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: igor.korotin.linux@...il.com
Cc: Danilo Krummrich <dakr@...nel.org>,
Miguel Ojeda <ojeda@...nel.org>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Wolfram Sang <wsa+renesas@...g-engineering.com>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org,
linux-i2c@...r.kernel.org,
markus.probst@...teo.de
Subject: Re: [PATCH 2/5] rust: bits: add define_flags macro
Igor,
> On 31 Jan 2026, at 11:12, Igor Korotin via B4 Relay <devnull+igor.korotin.linux.gmail.com@...nel.org> wrote:
>
> From: Igor Korotin <igor.korotin.linux@...il.com>
>
> introduce define_flags macro that incorporates BitOr BitAnd and Not
> implementations.
>
> Signed-off-by: Igor Korotin <igor.korotin.linux@...il.com>
> ---
> rust/kernel/bits.rs | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 57 insertions(+)
>
> diff --git a/rust/kernel/bits.rs b/rust/kernel/bits.rs
> index 553d50265883..6750aef18708 100644
> --- a/rust/kernel/bits.rs
> +++ b/rust/kernel/bits.rs
> @@ -201,3 +201,60 @@ pub const fn [<genmask_ $ty>](range: RangeInclusive<u32>) -> $ty {
> /// assert_eq!(genmask_u8(0..=7), u8::MAX);
> /// ```
> );
> +
> +/// defines flags
> +#[macro_export]
> +macro_rules! define_flags {
> + (
> + $gen_name:ident($gen_type:ident),
> + $($variant:ident = $binding:expr,)+
> + ) => {
> + /// Flags that can be combined with the operators `|`, `&`, and `!`.
> + ///
> + /// Values can be used from the [`flags`] module.
> + #[derive(Clone, Copy, PartialEq)]
> + pub struct $gen_name($gen_type);
> +
> + impl $gen_name {
> + /// Get the raw representation of this flag.
> + pub(crate) fn as_raw(self) -> $gen_type {
> + self.0
> + }
> +
> + /// Check whether `flags` is contained in `self`.
> + pub fn contains(self, flags: $gen_name) -> bool {
> + (self & flags) == flags
> + }
> + }
> +
> + impl core::ops::BitOr for $gen_name {
> + type Output = $gen_name;
> + fn bitor(self, rhs: Self) -> Self::Output {
> + Self(self.0 | rhs.0)
> + }
> + }
> +
> + impl core::ops::BitAnd for $gen_name {
> + type Output = $gen_name;
> + fn bitand(self, rhs: Self) -> Self::Output {
> + Self(self.0 & rhs.0)
> + }
> + }
> +
> + impl core::ops::Not for $gen_name {
> + type Output = $gen_name;
> + fn not(self) -> Self::Output {
> + Self(!self.0)
> + }
> + }
> +
> + #[allow(missing_docs)]
> + pub mod flags {
> + use super::$gen_name;
> + $(
> + #[allow(missing_docs)]
> + pub const $variant: $gen_name = $gen_name($binding as $gen_type);
> + )+
> + }
> + }
> +}
>
> --
> 2.43.0
>
>
>
Please drop this patch in favor of the patch from Filipe Xavier. It does the same thing.
— Daniel
Powered by blists - more mailing lists