pub const fn rust() -> &'static str {
""
}
pub const fn python() -> &'static str {
""
}
pub const fn javascript() -> &'static str {
""
}
pub const fn typescript() -> &'static str {
""
}
pub const fn go() -> &'static str {
""
}
pub const fn c() -> &'static str {
""
}
pub const fn cpp() -> &'static str {
""
}
pub const fn java() -> &'static str {
""
}
pub const fn ruby() -> &'static str {
""
}
pub const fn php() -> &'static str {
""
}
pub const fn swift() -> &'static str {
""
}
pub const fn kotlin() -> &'static str {
""
}
pub const fn lua() -> &'static str {
""
}
pub const fn vim() -> &'static str {
""
}
pub const fn shell() -> &'static str {
""
}
pub const fn html() -> &'static str {
""
}
pub const fn css() -> &'static str {
""
}
pub const fn sass() -> &'static str {
""
}
pub const fn json() -> &'static str {
""
}
pub const fn yaml() -> &'static str {
""
}
pub const fn toml() -> &'static str {
""
}
pub const fn xml() -> &'static str {
"謹"
}
pub const fn markdown() -> &'static str {
""
}
pub const fn text() -> &'static str {
""
}
pub const fn pdf() -> &'static str {
""
}
pub const fn image() -> &'static str {
""
}
pub const fn video() -> &'static str {
""
}
pub const fn audio() -> &'static str {
""
}
pub const fn archive() -> &'static str {
""
}
pub const fn binary() -> &'static str {
""
}
pub const fn lock() -> &'static str {
""
}
pub const fn config() -> &'static str {
""
}
pub const fn database() -> &'static str {
""
}
pub const fn docker() -> &'static str {
""
}
pub const fn makefile() -> &'static str {
""
}
pub const fn license() -> &'static str {
""
}
pub const fn readme() -> &'static str {
""
}
pub const fn gitfile() -> &'static str {
""
}
pub const fn npm() -> &'static str {
""
}
pub const fn cargo() -> &'static str {
""
}
pub const fn default() -> &'static str {
""
}
pub fn for_extension(ext: &str) -> &'static str {
match ext.to_lowercase().as_str() {
"rs" => rust(),
"py" | "pyw" | "pyi" => python(),
"js" | "mjs" | "cjs" => javascript(),
"ts" | "mts" | "cts" => typescript(),
"go" => go(),
"c" | "h" => c(),
"cpp" | "cc" | "cxx" | "hpp" | "hxx" => cpp(),
"java" => java(),
"rb" => ruby(),
"php" => php(),
"swift" => swift(),
"kt" | "kts" => kotlin(),
"lua" => lua(),
"vim" => vim(),
"sh" | "bash" | "zsh" | "fish" => shell(),
"html" | "htm" => html(),
"css" => css(),
"scss" | "sass" => sass(),
"json" => json(),
"yaml" | "yml" => yaml(),
"toml" => toml(),
"xml" => xml(),
"md" | "markdown" => markdown(),
"txt" => text(),
"pdf" => pdf(),
"png" | "jpg" | "jpeg" | "gif" | "bmp" | "svg" | "webp" | "ico" => image(),
"mp4" | "mkv" | "avi" | "mov" | "webm" => video(),
"mp3" | "wav" | "flac" | "ogg" | "m4a" => audio(),
"zip" | "tar" | "gz" | "bz2" | "xz" | "7z" | "rar" => archive(),
"exe" | "dll" | "so" | "dylib" | "bin" => binary(),
"lock" => lock(),
"db" | "sqlite" | "sqlite3" => database(),
_ => default(),
}
}
pub fn for_filename(name: &str) -> &'static str {
let lower = name.to_lowercase();
match lower.as_str() {
"cargo.toml" | "cargo.lock" => cargo(),
"dockerfile" | "docker-compose.yml" | "docker-compose.yaml" => docker(),
"makefile" | "gnumakefile" => makefile(),
"license" | "license.md" | "license.txt" => license(),
"readme" | "readme.md" | "readme.txt" => readme(),
".gitignore" | ".gitattributes" | ".gitmodules" => gitfile(),
"package.json" | "package-lock.json" => npm(),
_ => {
if let Some(ext) = name.rsplit('.').next() {
if ext != name {
return for_extension(ext);
}
}
default()
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_file_icons() {
assert_eq!(rust(), "");
assert_eq!(python(), "");
assert_eq!(javascript(), "");
}
#[test]
fn test_for_extension() {
assert_eq!(for_extension("rs"), "");
assert_eq!(for_extension("py"), "");
assert_eq!(for_extension("unknown"), default());
}
#[test]
fn test_for_filename() {
assert_eq!(for_filename("Cargo.toml"), cargo());
assert_eq!(for_filename("main.rs"), rust());
assert_eq!(for_filename("Dockerfile"), docker());
}
}