1#[derive(Clone, Copy, Debug, Eq, PartialEq)]
3#[repr(transparent)]
4pub struct Kind(libc::mode_t);
5
6impl Kind {
7 pub const fn from_dirent(value: u8) -> Option<Self> {
10 match value {
11 libc::DT_BLK
12 | libc::DT_CHR
13 | libc::DT_DIR
14 | libc::DT_FIFO
15 | libc::DT_LNK
16 | libc::DT_REG
17 | libc::DT_SOCK => Some(Self((value as libc::mode_t) << 12)),
18 _ => None,
19 }
20 }
21
22 pub const fn from_mode(mode: libc::mode_t) -> Self {
23 Self(mode & libc::S_IFMT)
24 }
25
26 pub const fn is_regular(self) -> bool {
28 self.0 == libc::S_IFREG
29 }
30
31 pub const fn is_dir(self) -> bool {
32 self.0 == libc::S_IFDIR
33 }
34
35 pub const fn is_symlink(self) -> bool {
36 self.0 == libc::S_IFLNK
37 }
38}