Skip to content

Commit fcb2bf6

Browse files
hoshinolinajannau
authored andcommitted
rust: alloc: Flags: Switch to declare_flags_type!() macro.
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent e7a80b7 commit fcb2bf6

1 file changed

Lines changed: 9 additions & 39 deletions

File tree

rust/kernel/alloc.rs

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,22 @@ pub use self::kvec::KVec;
1818
pub use self::kvec::VVec;
1919
pub use self::kvec::Vec;
2020

21+
use crate::types::declare_flags_type;
22+
2123
/// Indicates an allocation error.
2224
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
2325
pub struct AllocError;
2426

2527
use crate::error::{code::EINVAL, Result};
2628
use core::{alloc::Layout, ptr::NonNull};
2729

28-
/// Flags to be used when allocating memory.
29-
///
30-
/// They can be combined with the operators `|`, `&`, and `!`.
31-
///
32-
/// Values can be used from the [`flags`] module.
33-
#[derive(Clone, Copy, PartialEq)]
34-
pub struct Flags(u32);
35-
36-
impl Flags {
37-
/// Get the raw representation of this flag.
38-
pub(crate) fn as_raw(self) -> u32 {
39-
self.0
40-
}
41-
42-
/// Check whether `flags` is contained in `self`.
43-
pub fn contains(self, flags: Flags) -> bool {
44-
(self & flags) == flags
45-
}
46-
}
47-
48-
impl core::ops::BitOr for Flags {
49-
type Output = Self;
50-
fn bitor(self, rhs: Self) -> Self::Output {
51-
Self(self.0 | rhs.0)
52-
}
53-
}
54-
55-
impl core::ops::BitAnd for Flags {
56-
type Output = Self;
57-
fn bitand(self, rhs: Self) -> Self::Output {
58-
Self(self.0 & rhs.0)
59-
}
60-
}
61-
62-
impl core::ops::Not for Flags {
63-
type Output = Self;
64-
fn not(self) -> Self::Output {
65-
Self(!self.0)
66-
}
30+
declare_flags_type! {
31+
/// Flags to be used when allocating memory.
32+
///
33+
/// They can be combined with the operators `|`, `&`, and `!`.
34+
///
35+
/// Values can be used from the [`flags`] module.
36+
pub struct Flags(u32);
6737
}
6838

6939
/// Allocation flags.

0 commit comments

Comments
 (0)