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