1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// @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 {}