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 (`BMM_PARAMETER_DIRECTION`) — DO NOT EDIT.

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

/// Enumeration of parameter read/write direction values.
#[doc(alias = "BMM_PARAMETER_DIRECTION")]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BmmParameterDirection {
    /// `in`
    In,
    /// `out`
    Out,
    /// `in_out`
    InOut,
    /// A value outside the `BMM_PARAMETER_DIRECTION` 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 BmmParameterDirection {
    /// The wire string of this constant (the verbatim token for
    /// [`Self::Other`]).
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::In => "in",
            Self::Out => "out",
            Self::InOut => "in_out",
            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 {
            "in" => Self::In,
            "out" => Self::Out,
            "in_out" => Self::InOut,
            _ => Self::Other(__s.to_owned()),
        }
    }
}

impl ::core::convert::TryFrom<&str> for BmmParameterDirection {
    type Error = UnknownBmmParameterDirection;

    /// # Errors
    /// Returns [`UnknownBmmParameterDirection`] when `__s` is not a `BMM_PARAMETER_DIRECTION` value
    /// (unlike [`Self::from_wire`], which is total).
    fn try_from(__s: &str) -> ::core::result::Result<Self, Self::Error> {
        match __s {
            "in" => ::core::result::Result::Ok(Self::In),
            "out" => ::core::result::Result::Ok(Self::Out),
            "in_out" => ::core::result::Result::Ok(Self::InOut),
            _ => ::core::result::Result::Err(UnknownBmmParameterDirection(__s.to_owned())),
        }
    }
}

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

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

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