weirdnet_code_spaces/
lang.rs1use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
6#[serde(rename_all = "snake_case")]
7pub enum Lang {
8 Math,
10 Polars,
12 Rust,
14 Python,
16 Plugin,
18}
19
20impl Lang {
21 pub const ALL: [Lang; 5] = [Lang::Math, Lang::Polars, Lang::Rust, Lang::Python, Lang::Plugin];
22 pub fn as_str(self) -> &'static str {
23 match self {
24 Lang::Math => "math",
25 Lang::Polars => "polars",
26 Lang::Rust => "rust",
27 Lang::Python => "python",
28 Lang::Plugin => "plugin",
29 }
30 }
31 pub fn parse(s: &str) -> Option<Lang> {
32 Some(match s.trim().to_ascii_lowercase().as_str() {
33 "math" | "formula" | "formulas" => Lang::Math,
34 "polars" | "pl" => Lang::Polars,
35 "rust" | "rs" => Lang::Rust,
36 "python" | "py" | "rython" => Lang::Python,
37 "plugin" | "prebuilt" | "lib" => Lang::Plugin,
38 _ => return None,
39 })
40 }
41 pub fn compiled(self) -> bool {
43 self != Lang::Plugin
44 }
45 pub fn ext(self) -> &'static str {
47 match self {
48 Lang::Math => "math",
49 Lang::Polars => "polars",
50 Lang::Rust => "rs",
51 Lang::Python => "py",
52 Lang::Plugin => "txt",
53 }
54 }
55}