[PATCH 2/2] rust: impl_flags: add bitwise operations with the underlying type

From: Andreas Hindborg

Date: Sun Feb 15 2026 - 15:24:04 EST


Add bitwise or operations between the flag value enum and the underlying
type. This is useful when manipulating flags from C API without round
tripping into the Rust flag container type:

let mut lim: bindings::queue_limits = unsafe { core::mem::zeroed() };
...
if self.write_cache {
lim.features |= request::Feature::WriteCache;
}

The above code would be needlessly verbose without this direct assignment
option.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
rust/kernel/impl_flags.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/rust/kernel/impl_flags.rs b/rust/kernel/impl_flags.rs
index f34ecbe870d80..f829be815885e 100644
--- a/rust/kernel/impl_flags.rs
+++ b/rust/kernel/impl_flags.rs
@@ -245,6 +245,22 @@ fn bitxor(self, rhs: $flag) -> Self::Output {
}
}

+ impl ::core::ops::BitOr<$flag> for $ty {
+ type Output = Self;
+
+ #[inline]
+ fn bitor(self, rhs: $flag) -> Self::Output {
+ self | <$flag as Into<Self>>::into(rhs)
+ }
+ }
+
+ impl ::core::ops::BitOrAssign<$flag> for $ty {
+ #[inline]
+ fn bitor_assign(&mut self, rhs: $flag) {
+ *self = *self | <$flag as Into<Self>>::into(rhs)
+ }
+ }
+
impl $flags {
/// Returns an empty instance of `type` where no flags are set.
#[inline]

--
2.51.2