rust_filesearch/models/
category.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(tag = "type", rename_all = "lowercase")]
6pub enum FileCategory {
7 Source { language: String },
9 Build,
11 Config { format: String },
13 Documentation,
15 Media { media_type: MediaType },
17 Data { format: String },
19 Archive,
21 Executable,
23 Unknown,
25}
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "lowercase")]
30pub enum MediaType {
31 Image,
32 Video,
33 Audio,
34}
35
36impl FileCategory {
37 pub fn from_extension(ext: &str) -> Self {
39 match ext.to_lowercase().as_str() {
40 "rs" => FileCategory::Source {
42 language: "rust".to_string(),
43 },
44 "go" => FileCategory::Source {
45 language: "go".to_string(),
46 },
47 "py" => FileCategory::Source {
48 language: "python".to_string(),
49 },
50 "js" | "jsx" | "ts" | "tsx" => FileCategory::Source {
51 language: "javascript".to_string(),
52 },
53 "java" => FileCategory::Source {
54 language: "java".to_string(),
55 },
56 "c" | "h" => FileCategory::Source {
57 language: "c".to_string(),
58 },
59 "cpp" | "cc" | "cxx" | "hpp" => FileCategory::Source {
60 language: "cpp".to_string(),
61 },
62 "rb" => FileCategory::Source {
63 language: "ruby".to_string(),
64 },
65 "php" => FileCategory::Source {
66 language: "php".to_string(),
67 },
68 "swift" => FileCategory::Source {
69 language: "swift".to_string(),
70 },
71 "kt" | "kts" => FileCategory::Source {
72 language: "kotlin".to_string(),
73 },
74
75 "o" | "so" | "dylib" | "dll" | "a" | "lib" => FileCategory::Build,
77
78 "toml" => FileCategory::Config {
80 format: "toml".to_string(),
81 },
82 "yaml" | "yml" => FileCategory::Config {
83 format: "yaml".to_string(),
84 },
85 "json" => FileCategory::Config {
86 format: "json".to_string(),
87 },
88 "ini" | "conf" | "cfg" => FileCategory::Config {
89 format: "ini".to_string(),
90 },
91
92 "md" | "markdown" => FileCategory::Documentation,
94 "txt" | "rst" | "adoc" => FileCategory::Documentation,
95 "pdf" | "tex" => FileCategory::Documentation,
96
97 "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "svg" | "ico" => {
99 FileCategory::Media {
100 media_type: MediaType::Image,
101 }
102 }
103
104 "mp4" | "mkv" | "avi" | "mov" | "wmv" | "flv" | "webm" => FileCategory::Media {
106 media_type: MediaType::Video,
107 },
108
109 "mp3" | "wav" | "flac" | "aac" | "ogg" | "m4a" | "wma" => FileCategory::Media {
111 media_type: MediaType::Audio,
112 },
113
114 "csv" | "tsv" => FileCategory::Data {
116 format: "csv".to_string(),
117 },
118 "xml" => FileCategory::Data {
119 format: "xml".to_string(),
120 },
121 "db" | "sqlite" | "sqlite3" => FileCategory::Data {
122 format: "sqlite".to_string(),
123 },
124 "parquet" => FileCategory::Data {
125 format: "parquet".to_string(),
126 },
127
128 "zip" | "tar" | "gz" | "bz2" | "xz" | "7z" | "rar" => FileCategory::Archive,
130
131 "sh" | "bash" | "zsh" | "fish" => FileCategory::Executable,
133
134 _ => FileCategory::Unknown,
135 }
136 }
137}