openehr-lang 0.0.128

openEHR LANG BMM/P_BMM object model, generated from BMM: generations v1_0 (LANG 1.0.0) and v1_1 (LANG 1.1.0, current; the stable BMM v2.x unit beside the paused BMM3 unit), plus hand-written ODIN/BEL/EL readers
Documentation
// @generated by openehr-codegen from BMM (`BMM_SCHEMA_STATE`) — DO NOT EDIT.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-FileCopyrightText: openEHR Foundation
// SPDX-License-Identifier: Apache-2.0

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

/// Enumeration of processing states of a `BMM_SCHEMA` used by creation and validation routines in `BMM_SCHEMA`.
#[doc(alias = "BMM_SCHEMA_STATE")]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BmmSchemaState {
    /// `State_created`
    StateCreated,
    /// `State_validated_created`
    StateValidatedCreated,
    /// `State_includes_pending`
    StateIncludesPending,
    /// `State_includes_processed`
    StateIncludesProcessed,
    /// A value outside the `BMM_SCHEMA_STATE` 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 BmmSchemaState {
    /// The wire string of this constant (the verbatim token for
    /// [`Self::Other`]).
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::StateCreated => "State_created",
            Self::StateValidatedCreated => "State_validated_created",
            Self::StateIncludesPending => "State_includes_pending",
            Self::StateIncludesProcessed => "State_includes_processed",
            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 {
            "State_created" => Self::StateCreated,
            "State_validated_created" => Self::StateValidatedCreated,
            "State_includes_pending" => Self::StateIncludesPending,
            "State_includes_processed" => Self::StateIncludesProcessed,
            _ => Self::Other(__s.to_owned()),
        }
    }
}

impl ::core::convert::TryFrom<&str> for BmmSchemaState {
    type Error = UnknownBmmSchemaState;

    /// # Errors
    /// Returns [`UnknownBmmSchemaState`] when `__s` is not a `BMM_SCHEMA_STATE` value
    /// (unlike [`Self::from_wire`], which is total).
    fn try_from(__s: &str) -> ::core::result::Result<Self, Self::Error> {
        match __s {
            "State_created" => ::core::result::Result::Ok(Self::StateCreated),
            "State_validated_created" => ::core::result::Result::Ok(Self::StateValidatedCreated),
            "State_includes_pending" => ::core::result::Result::Ok(Self::StateIncludesPending),
            "State_includes_processed" => ::core::result::Result::Ok(Self::StateIncludesProcessed),
            _ => ::core::result::Result::Err(UnknownBmmSchemaState(__s.to_owned())),
        }
    }
}

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

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

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