openehr-rm 0.0.128

openEHR RM Reference Model, generated from BMM: generations v1_1 (RM 1.1.0) and v1_2 (RM 1.2.0, current)
Documentation
// @generated by openehr-codegen from BMM (`VIEW_STATUS`) — DO NOT EDIT.
// SPDX-FileCopyrightText: Cadasto B.V.
// SPDX-FileCopyrightText: openEHR Foundation
// SPDX-License-Identifier: Apache-2.0

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

/// The openEHR `VIEW_STATUS` class (the vendored BMM carries no documentation for it).
#[doc(alias = "VIEW_STATUS")]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ViewStatus {
    /// `active`
    Active,
    /// `inactive`
    Inactive,
    /// A value outside the `VIEW_STATUS` 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 ViewStatus {
    /// The wire string of this constant (the verbatim token for
    /// [`Self::Other`]).
    #[must_use]
    pub fn as_str(&self) -> &str {
        match self {
            Self::Active => "active",
            Self::Inactive => "inactive",
            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 {
            "active" => Self::Active,
            "inactive" => Self::Inactive,
            _ => Self::Other(__s.to_owned()),
        }
    }
}

impl ::core::convert::TryFrom<&str> for ViewStatus {
    type Error = UnknownViewStatus;

    /// # Errors
    /// Returns [`UnknownViewStatus`] when `__s` is not a `VIEW_STATUS` value
    /// (unlike [`Self::from_wire`], which is total).
    fn try_from(__s: &str) -> ::core::result::Result<Self, Self::Error> {
        match __s {
            "active" => ::core::result::Result::Ok(Self::Active),
            "inactive" => ::core::result::Result::Ok(Self::Inactive),
            _ => ::core::result::Result::Err(UnknownViewStatus(__s.to_owned())),
        }
    }
}

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

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

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