jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @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::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Deserialize, Serialize};
/// 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<S: BosStr = DefaultStr> {
    Python,
    Typescript,
    Javascript,
    Rust,
    Other(S),
}

impl<S: BosStr> ProgrammingLanguage<S> {
    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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "python" => Self::Python,
            "typescript" => Self::Typescript,
            "javascript" => Self::Javascript,
            "rust" => Self::Rust,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> AsRef<str> for ProgrammingLanguage<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

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

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ProgrammingLanguage<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ProgrammingLanguage<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ProgrammingLanguage<S::Output>;
    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")
    }
}