Skip to content

Commit 9da656c

Browse files
Danilo Krummrichfbq
Danilo Krummrich
authored andcommitted
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 <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Gary Guo <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 817ad57 commit 9da656c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rust/kernel/alloc.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,19 @@ use core::{alloc::Layout, ptr::NonNull};
3535
/// They can be combined with the operators `|`, `&`, and `!`.
3636
///
3737
/// Values can be used from the [`flags`] module.
38-
#[derive(Clone, Copy)]
38+
#[derive(Clone, Copy, PartialEq)]
3939
pub struct Flags(u32);
4040

4141
impl Flags {
4242
/// Get the raw representation of this flag.
4343
pub(crate) fn as_raw(self) -> u32 {
4444
self.0
4545
}
46+
47+
/// Check whether `flags` is contained in `self`.
48+
pub fn contains(self, flags: Flags) -> bool {
49+
(self & flags) == flags
50+
}
4651
}
4752

4853
impl core::ops::BitOr for Flags {

0 commit comments

Comments
 (0)