openat/
filetype.rs

1use std::fs::Metadata;
2
3/// This is a simplified file type enum that is easy to match
4///
5/// It doesn't represent all the options, because that enum needs to extensible
6/// but most application do not actually need that power, so we provide
7/// this simplified enum that works for many appalications.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum SimpleType {
10    /// Entry is a symlink
11    Symlink,
12    /// Entry is a directory
13    Dir,
14    /// Entry is a regular file
15    File,
16    /// Entry is neither a symlink, directory nor a regular file
17    Other,
18}
19
20impl SimpleType {
21    /// Find out a simple type from a file Metadata (stat)
22    pub fn extract(stat: &Metadata) -> SimpleType {
23        if stat.file_type().is_symlink() {
24            SimpleType::Symlink
25        } else if stat.is_dir() {
26            SimpleType::Dir
27        } else if stat.is_file() {
28            SimpleType::File
29        } else {
30            SimpleType::Other
31        }
32    }
33}