Skip to content

Commit da2b933

Browse files
Danilo Krummrichfbq
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]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f04f9d7 commit da2b933

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rust/kernel/alloc.rs

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

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

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

0 commit comments

Comments
 (0)