From: Andreas Hindborg <a.hindborg@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Boqun Feng" <boqun@kernel.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Andreas Hindborg <a.hindborg@kernel.org>
Subject: [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the underlying type
Date: Fri, 05 Jun 2026 15:04:39 +0200 [thread overview]
Message-ID: <20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org> (raw)
In-Reply-To: <20260605-impl-flags-additions-v2-0-0d27242f460b@kernel.org>
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@kernel.org>
---
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 04a4b0a356df..8340740b2efb 100644
--- a/rust/kernel/impl_flags.rs
+++ b/rust/kernel/impl_flags.rs
@@ -280,6 +280,22 @@ fn not(self) -> 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 where no flags are set.
#[inline]
--
2.51.2
next prev parent reply other threads:[~2026-06-05 13:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 13:04 [PATCH v2 0/2] rust: impl_flags: add convenience functions Andreas Hindborg
2026-06-05 13:04 ` [PATCH v2 1/2] rust: impl_flags: add conversion functions Andreas Hindborg
2026-06-05 18:17 ` Miguel Ojeda
2026-06-05 13:04 ` Andreas Hindborg [this message]
2026-06-05 18:20 ` [PATCH v2 2/2] rust: impl_flags: add bitwise operations with the underlying type Miguel Ojeda
2026-06-06 8:09 ` Andreas Hindborg
2026-06-06 11:21 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260605-impl-flags-additions-v2-2-0d27242f460b@kernel.org \
--to=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox