openehr-am 0.0.78

openEHR AM Archetype Model, generated from BMM: generations v1_4 (AM 1.4.0, ADL 1.4) and v2_4 (AM 2.4.0, ADL 2; current)
Documentation
// @generated by openehr-codegen from BMM (`CONSTRAINT_STATUS`) — DO NOT EDIT.
// SPDX-FileCopyrightText: Vernum Projecten B.V.
// SPDX-FileCopyrightText: openEHR Foundation
// SPDX-License-Identifier: Apache-2.0

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

/// Status of `_constraint_`, with values allowing for 'soft' constraints, which are effectively different kinds of suggestions.
#[doc(alias = "CONSTRAINT_STATUS")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ConstraintStatus {
    /// `required` = 0
    Required,
    /// `extensible` = 1
    Extensible,
    /// `preferred` = 2
    Preferred,
    /// `example` = 3
    Example,
    /// A value outside the `CONSTRAINT_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 `i32` it replaces.
    Other(i32),
}

impl ConstraintStatus {
    /// The `i32` wire value of this constant (the verbatim payload for
    /// [`Self::Other`]).
    #[must_use]
    pub fn value(self) -> i32 {
        match self {
            Self::Required => 0,
            Self::Extensible => 1,
            Self::Preferred => 2,
            Self::Example => 3,
            Self::Other(__v) => __v,
        }
    }

    /// This constant for an `i32` wire value, tolerating an unknown
    /// value as [`Self::Other`] (total — never fails).
    #[must_use]
    pub fn from_value(__v: i32) -> Self {
        match __v {
            0 => Self::Required,
            1 => Self::Extensible,
            2 => Self::Preferred,
            3 => Self::Example,
            _ => Self::Other(__v),
        }
    }
}

impl ::core::convert::TryFrom<i64> for ConstraintStatus {
    type Error = UnknownConstraintStatus;

    /// # Errors
    /// Returns [`UnknownConstraintStatus`] when `__v` is not a `CONSTRAINT_STATUS` value
    /// (unlike [`Self::from_value`], which is total).
    fn try_from(__v: i64) -> ::core::result::Result<Self, Self::Error> {
        match __v {
            0 => ::core::result::Result::Ok(Self::Required),
            1 => ::core::result::Result::Ok(Self::Extensible),
            2 => ::core::result::Result::Ok(Self::Preferred),
            3 => ::core::result::Result::Ok(Self::Example),
            _ => ::core::result::Result::Err(UnknownConstraintStatus(__v)),
        }
    }
}

/// The error returned by [`ConstraintStatus::try_from`] for a value outside the `CONSTRAINT_STATUS`
/// constant set.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownConstraintStatus(pub i64);

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

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