summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2024-10-04 17:41:28 +0200
committerMiguel Ojeda <ojeda@kernel.org>2024-10-15 23:10:32 +0200
commit909037ce0369bc3f4fd31743fd2d8d7096f06002 (patch)
treee5c03b85efd8a1beb30b336fc0bc1a684a9cdc54 /rust
parent4a28ab469ff01855eb819dfd94754d1792f03f2a (diff)
rust: alloc: implement `contains` for `Flags`
Provide a simple helper function to check whether given flags do contain one or multiple other flags. This is used by a subsequent patch implementing the Cmalloc `Allocator` to check for __GFP_ZERO. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Gary Guo <gary@garyguo.net> Signed-off-by: Danilo Krummrich <dakr@kernel.org> Link: https://lore.kernel.org/r/20241004154149.93856-25-dakr@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/alloc.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
index 7fc2e404e594..049fca7a514d 100644
--- a/rust/kernel/alloc.rs
+++ b/rust/kernel/alloc.rs
@@ -35,7 +35,7 @@ use core::{alloc::Layout, ptr::NonNull};
/// They can be combined with the operators `|`, `&`, and `!`.
///
/// Values can be used from the [`flags`] module.
-#[derive(Clone, Copy)]
+#[derive(Clone, Copy, PartialEq)]
pub struct Flags(u32);
impl Flags {
@@ -43,6 +43,11 @@ impl Flags {
pub(crate) fn as_raw(self) -> u32 {
self.0
}
+
+ /// Check whether `flags` is contained in `self`.
+ pub fn contains(self, flags: Flags) -> bool {
+ (self & flags) == flags
+ }
}
impl core::ops::BitOr for Flags {