openehr-lang 0.0.2

openEHR LANG 1.0.0: BMM/P_BMM object model (generated from BMM) plus a hand-written ODIN instance parser (the `odin` module — deliberately off the codegen path).
Documentation
// @generated by openehr-codegen from BMM (`OPERATOR_KIND`) — DO NOT EDIT.

//! The openEHR `OPERATOR_KIND` spec class, generated from the vendored BMM
//! meta-model.

/// Enumeration representing operators.
#[doc(alias = "OPERATOR_KIND")]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum OperatorKind {
    /// `eq`
    Eq,
    /// `ne`
    Ne,
    /// `lt`
    Lt,
    /// `le`
    Le,
    /// `gt`
    Gt,
    /// `ge`
    Ge,
    /// `matches`
    Matches,
    /// `not`
    Not,
    /// `and`
    And,
    /// `or`
    Or,
    /// `xor`
    Xor,
    /// `implies`
    Implies,
    /// `for_all`
    ForAll,
    /// `exists`
    Exists,
    /// `plus`
    Plus,
    /// `minus`
    Minus,
    /// `multiply`
    Multiply,
    /// `divide`
    Divide,
    /// `modulo`
    Modulo,
    /// `exponent`
    Exponent,
    /// A value outside the `OPERATOR_KIND` constant set.
    ///
    /// NOTE: no openEHR spec governs an out-of-set value — our own
    /// tolerance-preserving design (`BMM_ENUMERATION` defines only the listed
    /// constants), retained so this enum's wire form stays byte-identical to
    /// the bare `String` it replaces.
    Other(String),
}

impl OperatorKind {
    /// The wire string of this constant (the verbatim token for
    /// [`Self::Other`]).
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Eq => "eq",
            Self::Ne => "ne",
            Self::Lt => "lt",
            Self::Le => "le",
            Self::Gt => "gt",
            Self::Ge => "ge",
            Self::Matches => "matches",
            Self::Not => "not",
            Self::And => "and",
            Self::Or => "or",
            Self::Xor => "xor",
            Self::Implies => "implies",
            Self::ForAll => "for_all",
            Self::Exists => "exists",
            Self::Plus => "plus",
            Self::Minus => "minus",
            Self::Multiply => "multiply",
            Self::Divide => "divide",
            Self::Modulo => "modulo",
            Self::Exponent => "exponent",
            Self::Other(__s) => __s.as_str(),
        }
    }

    /// This constant for a wire string, tolerating an unknown token
    /// as [`Self::Other`] (total — never fails).
    #[must_use]
    pub fn from_wire(__s: &str) -> Self {
        match __s {
            "eq" => Self::Eq,
            "ne" => Self::Ne,
            "lt" => Self::Lt,
            "le" => Self::Le,
            "gt" => Self::Gt,
            "ge" => Self::Ge,
            "matches" => Self::Matches,
            "not" => Self::Not,
            "and" => Self::And,
            "or" => Self::Or,
            "xor" => Self::Xor,
            "implies" => Self::Implies,
            "for_all" => Self::ForAll,
            "exists" => Self::Exists,
            "plus" => Self::Plus,
            "minus" => Self::Minus,
            "multiply" => Self::Multiply,
            "divide" => Self::Divide,
            "modulo" => Self::Modulo,
            "exponent" => Self::Exponent,
            _ => Self::Other(__s.to_owned()),
        }
    }
}

impl ::core::convert::TryFrom<&str> for OperatorKind {
    type Error = UnknownOperatorKind;

    /// # Errors
    /// Returns [`UnknownOperatorKind`] when `__s` is not a `OPERATOR_KIND` value
    /// (unlike [`Self::from_wire`], which is total).
    fn try_from(__s: &str) -> ::core::result::Result<Self, Self::Error> {
        match __s {
            "eq" => ::core::result::Result::Ok(Self::Eq),
            "ne" => ::core::result::Result::Ok(Self::Ne),
            "lt" => ::core::result::Result::Ok(Self::Lt),
            "le" => ::core::result::Result::Ok(Self::Le),
            "gt" => ::core::result::Result::Ok(Self::Gt),
            "ge" => ::core::result::Result::Ok(Self::Ge),
            "matches" => ::core::result::Result::Ok(Self::Matches),
            "not" => ::core::result::Result::Ok(Self::Not),
            "and" => ::core::result::Result::Ok(Self::And),
            "or" => ::core::result::Result::Ok(Self::Or),
            "xor" => ::core::result::Result::Ok(Self::Xor),
            "implies" => ::core::result::Result::Ok(Self::Implies),
            "for_all" => ::core::result::Result::Ok(Self::ForAll),
            "exists" => ::core::result::Result::Ok(Self::Exists),
            "plus" => ::core::result::Result::Ok(Self::Plus),
            "minus" => ::core::result::Result::Ok(Self::Minus),
            "multiply" => ::core::result::Result::Ok(Self::Multiply),
            "divide" => ::core::result::Result::Ok(Self::Divide),
            "modulo" => ::core::result::Result::Ok(Self::Modulo),
            "exponent" => ::core::result::Result::Ok(Self::Exponent),
            _ => ::core::result::Result::Err(UnknownOperatorKind(__s.to_owned())),
        }
    }
}

/// The error returned by [`OperatorKind::try_from`] for a value outside the `OPERATOR_KIND`
/// constant set.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownOperatorKind(pub String);

impl ::core::fmt::Display for UnknownOperatorKind {
    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
        ::core::write!(f, "unknown OPERATOR_KIND value: {:?}", self.0)
    }
}

impl ::std::error::Error for UnknownOperatorKind {}