// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: science.alt.dataset.programmingLanguage
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

use jacquard_common::CowStr;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
/// JavaScript programming language.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Javascript;
impl core::fmt::Display for Javascript {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "javascript")
    }
}

/// Programming language identifier for code references. Uses Linguist language identifiers (lowercase). Known values correspond to token definitions in this Lexicon. New languages can be added as tokens without breaking changes.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ProgrammingLanguage<'a> {
    Python,
    Typescript,
    Javascript,
    Rust,
    Other(CowStr<'a>),
}

impl<'a> ProgrammingLanguage<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Python => "python",
            Self::Typescript => "typescript",
            Self::Javascript => "javascript",
            Self::Rust => "rust",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ProgrammingLanguage<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "python" => Self::Python,
            "typescript" => Self::Typescript,
            "javascript" => Self::Javascript,
            "rust" => Self::Rust,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ProgrammingLanguage<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "python" => Self::Python,
            "typescript" => Self::Typescript,
            "javascript" => Self::Javascript,
            "rust" => Self::Rust,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> AsRef<str> for ProgrammingLanguage<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<'a> core::fmt::Display for ProgrammingLanguage<'a> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<'a> serde::Serialize for ProgrammingLanguage<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for ProgrammingLanguage<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl jacquard_common::IntoStatic for ProgrammingLanguage<'_> {
    type Output = ProgrammingLanguage<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            ProgrammingLanguage::Python => ProgrammingLanguage::Python,
            ProgrammingLanguage::Typescript => ProgrammingLanguage::Typescript,
            ProgrammingLanguage::Javascript => ProgrammingLanguage::Javascript,
            ProgrammingLanguage::Rust => ProgrammingLanguage::Rust,
            ProgrammingLanguage::Other(v) => ProgrammingLanguage::Other(v.into_static()),
        }
    }
}

/// Python programming language.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Python;
impl core::fmt::Display for Python {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "python")
    }
}

/// Rust programming language.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Rust;
impl core::fmt::Display for Rust {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "rust")
    }
}

/// TypeScript programming language.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Typescript;
impl core::fmt::Display for Typescript {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "typescript")
    }
}