1use std::ops;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5#[repr(transparent)]
6pub struct Open(libc::c_int);
7
8impl Open {
9 pub const NONE: Self = Self(0);
10 pub const READ: Self = Self(libc::O_RDONLY);
11 pub const WRITE: Self = Self(libc::O_WRONLY);
12 pub const READ_WRITE: Self = Self(libc::O_RDWR);
13 pub const DIRECTORY: Self = Self(libc::O_RDONLY | libc::O_DIRECTORY);
14 pub const CREATE: Self = Self(libc::O_CREAT);
15 pub const EXCLUSIVE: Self = Self(libc::O_EXCL);
16 pub const APPEND: Self = Self(libc::O_APPEND);
17 pub const TRUNCATE: Self = Self(libc::O_TRUNC);
18 pub const NO_FOLLOW: Self = Self(libc::O_NOFOLLOW);
19 pub const NONBLOCK: Self = Self(libc::O_NONBLOCK);
20 pub const CLOSE_ON_EXEC: Self = Self(libc::O_CLOEXEC);
21
22 pub const fn union(self, other: Self) -> Self {
23 Self(self.0 | other.0)
24 }
25
26 pub const fn difference(self, other: Self) -> Self {
27 Self(self.0 & !other.0)
28 }
29
30 pub const fn contains(self, other: Self) -> bool {
31 self.0 & other.0 == other.0
32 }
33
34 pub const fn raw(self) -> libc::c_int {
35 self.0
36 }
37}
38
39impl ops::BitOr for Open {
40 type Output = Self;
41
42 fn bitor(self, other: Self) -> Self {
43 Self(self.0 | other.0)
44 }
45}