Skip to main content

openehr_term/
lib.rs

1// @generated by openehr-codegen — DO NOT EDIT.
2// SPDX-FileCopyrightText: Cadasto B.V.
3// SPDX-FileCopyrightText: openEHR Foundation
4// SPDX-License-Identifier: Apache-2.0
5//! openEHR TERM (Terminology) data model, generated from the BMM meta-model. The vendored terminology XML content lives in `assets/` (data, not generated); an XML→model loader is added when composition validation needs it.
6//!
7//! The type files are generated; hand-written spec behaviour
8//! lives in sibling `*_impl.rs` files.
9
10#![allow(
11    clippy::doc_markdown,
12    clippy::doc_link_with_quotes,
13    clippy::tabs_in_doc_comments,
14    clippy::doc_lazy_continuation,
15    clippy::doc_overindented_list_items,
16    clippy::struct_excessive_bools,
17    clippy::struct_field_names,
18    clippy::module_inception,
19    clippy::large_enum_variant,
20    clippy::enum_variant_names,
21    reason = "inherent to faithful openEHR spec generation: verbatim spec prose in doc comments, and spec-owned class/variant/field names (a field name IS the normative BMM attribute name)"
22)]
23// The generation preludes ARE this crate's public surface: the crate prelude re-exports the current generation, and each generation module re-exports its own types. That is the design (codegen.md), and it is the one place `clippy::pub_use` is satisfied by an exception rather than by removal. `expect` rather than `allow`: if a crate ever stops re-exporting, the exception self-reports instead of outliving its reason.
24#![expect(
25    clippy::pub_use,
26    reason = "the generation preludes are this crate's public surface"
27)]
28// A vendored BMM model is a deep, mutually-recursive type graph (the LANG // BMM-3 expression/statement families reach several hundred levels), so // auto-trait inference — `Send`/`Sync`/`RefUnwindSafe`, which rustdoc // evaluates for every item — overflows the default limit of 128. Raising // the limit is exactly what rustc prescribes for that overflow // (<https://doc.rust-lang.org/reference/attributes/limits.html>); it // changes no emitted type.
29#![recursion_limit = "512"]
30
31pub mod prelude;
32pub mod v3_1;
33
34/// The BMM generations this crate emits, one variant per version module,
35/// oldest first.
36///
37/// Generated from the openehr-codegen composition table — the single
38/// authority for which generations exist. [`std::fmt::Display`] and
39/// [`std::str::FromStr`] round-trip the generation-module name (`"v3_1"`). `Generation::default()` is the crate's CURRENT generation — the
40/// one `crate::prelude` re-exports (the composition table's `current`
41/// marker, via the std `#[default]` variant attribute).
42#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
43pub enum Generation {
44    /// The `v3_1` generation — openEHR specification version 3.1.0.
45    #[default]
46    V3_1,
47}
48
49impl Generation {
50    /// Returns the openEHR specification version this generation implements.
51    #[must_use]
52    pub const fn spec_version(self) -> &'static str {
53        match self {
54            Self::V3_1 => "3.1.0",
55        }
56    }
57
58    /// Returns the generation token — the version-module name
59    /// (`"v3_1"`), which is also the [`std::fmt::Display`] and
60    /// [`std::str::FromStr`] form.
61    #[must_use]
62    pub const fn as_str(self) -> &'static str {
63        match self {
64            Self::V3_1 => "v3_1",
65        }
66    }
67}
68
69impl std::fmt::Display for Generation {
70    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71        f.write_str(self.as_str())
72    }
73}
74
75/// Error returned when parsing a [`Generation`] from an unknown token.
76///
77/// The valid tokens are the generation-module names (`v3_1`).
78#[derive(Debug, Clone, PartialEq, Eq)]
79pub struct GenerationParseError {
80    unrecognized: String,
81}
82
83impl std::fmt::Display for GenerationParseError {
84    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85        write!(
86            f,
87            "unknown generation {:?} (valid: `v3_1`)",
88            self.unrecognized
89        )
90    }
91}
92
93impl std::error::Error for GenerationParseError {}
94
95impl std::str::FromStr for Generation {
96    type Err = GenerationParseError;
97
98    fn from_str(s: &str) -> Result<Self, Self::Err> {
99        match s {
100            "v3_1" => Ok(Self::V3_1),
101            other => Err(GenerationParseError {
102                unrecognized: other.to_owned(),
103            }),
104        }
105    }
106}
107
108// hand-written modules (spec behaviour), auto-declared:
109pub mod bundle;
110pub mod codes;
111pub mod measurement;
112
113// canonical-JSON `serde` impls (openehr-codegen -- emit-json), auto-declared:
114mod json_serde;