1#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
7pub struct IoFlags(pub(crate) u16);
8
9impl IoFlags {
10 pub const MEM_RESIDENT: Self = IoFlags(0x00);
12 pub const MEM_MAP: Self = IoFlags(0x01);
14 pub const READ_ONLY: Self = IoFlags(0x02);
16}
17
18impl Default for IoFlags {
19 fn default() -> Self {
20 IoFlags::MEM_RESIDENT
21 }
22}
23
24impl std::ops::BitOr for IoFlags {
25 type Output = Self;
26
27 fn bitor(self, rhs: Self) -> Self::Output {
28 Self(self.0 | rhs.0)
29 }
30}
31
32impl From<i32> for IoFlags {
33 fn from(n: i32) -> IoFlags {
34 IoFlags(n as u16)
35 }
36}
37
38impl From<IoFlags> for i32 {
39 fn from(io_flag: IoFlags) -> i32 {
40 io_flag.0 as i32
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn can_do_bitor() {
50 let mmap = IoFlags::MEM_MAP;
51 let ro = IoFlags::READ_ONLY;
52 assert_eq!(IoFlags(0x03), mmap | ro);
53 }
54
55 #[test]
56 fn can_coerce_to_i32() {
57 let mmap = IoFlags::MEM_MAP;
58 assert_eq!(1, mmap.into());
59 }
60}