1use std::collections::HashSet;
2use std::sync::LazyLock;
3
4pub const DIRECTORY: &str = "directory";
5pub const SYMLINK: &str = "symlink";
6pub const SOCKET: &str = "socket";
7pub const FILE: &str = "file";
8pub const EXECUTABLE: &str = "executable";
9pub const NON_EXECUTABLE: &str = "non-executable";
10pub const TEXT: &str = "text";
11pub const BINARY: &str = "binary";
12
13pub type TagSet = HashSet<&'static str>;
14
15#[inline]
17pub fn tags_from_array(tags: &[&'static str]) -> TagSet {
18 tags.iter().copied().collect()
19}
20
21pub static TYPE_TAGS: LazyLock<TagSet> =
22 LazyLock::new(|| HashSet::from([DIRECTORY, FILE, SYMLINK, SOCKET]));
23pub static MODE_TAGS: LazyLock<TagSet> =
24 LazyLock::new(|| HashSet::from([EXECUTABLE, NON_EXECUTABLE]));
25pub static ENCODING_TAGS: LazyLock<TagSet> = LazyLock::new(|| HashSet::from([BINARY, TEXT]));
26
27pub fn is_type_tag(tag: &str) -> bool {
29 matches!(tag, DIRECTORY | FILE | SYMLINK | SOCKET)
30}
31
32pub fn is_mode_tag(tag: &str) -> bool {
34 matches!(tag, EXECUTABLE | NON_EXECUTABLE)
35}
36
37pub fn is_encoding_tag(tag: &str) -> bool {
39 matches!(tag, BINARY | TEXT)
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
44pub enum FileKind {
45 Regular,
46 Directory,
47 Symlink,
48 Socket,
49}