use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Lang {
Math,
Polars,
Rust,
Python,
Plugin,
}
impl Lang {
pub const ALL: [Lang; 5] = [Lang::Math, Lang::Polars, Lang::Rust, Lang::Python, Lang::Plugin];
pub fn as_str(self) -> &'static str {
match self {
Lang::Math => "math",
Lang::Polars => "polars",
Lang::Rust => "rust",
Lang::Python => "python",
Lang::Plugin => "plugin",
}
}
pub fn parse(s: &str) -> Option<Lang> {
Some(match s.trim().to_ascii_lowercase().as_str() {
"math" | "formula" | "formulas" => Lang::Math,
"polars" | "pl" => Lang::Polars,
"rust" | "rs" => Lang::Rust,
"python" | "py" | "rython" => Lang::Python,
"plugin" | "prebuilt" | "lib" => Lang::Plugin,
_ => return None,
})
}
pub fn compiled(self) -> bool {
self != Lang::Plugin
}
pub fn ext(self) -> &'static str {
match self {
Lang::Math => "math",
Lang::Polars => "polars",
Lang::Rust => "rs",
Lang::Python => "py",
Lang::Plugin => "txt",
}
}
}