Skip to main content

openehr_am/
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 AM (Archetype Model): `v1_4` (AM 1.4.0, for ADL 1.4) and `v2_4` (AM 2.4.0, for ADL 2) — both generated from BMM. Both ADL versions are in use.
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 v1_4;
33pub mod v2_4;
34
35/// The BMM generations this crate emits, one variant per version module,
36/// oldest first.
37///
38/// Generated from the openehr-codegen composition table — the single
39/// authority for which generations exist. [`std::fmt::Display`] and
40/// [`std::str::FromStr`] round-trip the generation-module name (`"v1_4"`). `Generation::default()` is the crate's CURRENT generation — the
41/// one `crate::prelude` re-exports (the composition table's `current`
42/// marker, via the std `#[default]` variant attribute).
43#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
44pub enum Generation {
45    /// The `v1_4` generation — openEHR specification version 1.4.0.
46    V1_4,
47    /// The `v2_4` generation — openEHR specification version 2.4.0.
48    #[default]
49    V2_4,
50}
51
52impl Generation {
53    /// Returns the openEHR specification version this generation implements.
54    #[must_use]
55    pub const fn spec_version(self) -> &'static str {
56        match self {
57            Self::V1_4 => "1.4.0",
58            Self::V2_4 => "2.4.0",
59        }
60    }
61
62    /// Returns the generation token — the version-module name
63    /// (`"v2_4"`), which is also the [`std::fmt::Display`] and
64    /// [`std::str::FromStr`] form.
65    #[must_use]
66    pub const fn as_str(self) -> &'static str {
67        match self {
68            Self::V1_4 => "v1_4",
69            Self::V2_4 => "v2_4",
70        }
71    }
72}
73
74impl std::fmt::Display for Generation {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        f.write_str(self.as_str())
77    }
78}
79
80/// Error returned when parsing a [`Generation`] from an unknown token.
81///
82/// The valid tokens are the generation-module names (`v1_4`, `v2_4`).
83#[derive(Debug, Clone, PartialEq, Eq)]
84pub struct GenerationParseError {
85    unrecognized: String,
86}
87
88impl std::fmt::Display for GenerationParseError {
89    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90        write!(
91            f,
92            "unknown generation {:?} (valid: `v1_4`, `v2_4`)",
93            self.unrecognized
94        )
95    }
96}
97
98impl std::error::Error for GenerationParseError {}
99
100impl std::str::FromStr for Generation {
101    type Err = GenerationParseError;
102
103    fn from_str(s: &str) -> Result<Self, Self::Err> {
104        match s {
105            "v1_4" => Ok(Self::V1_4),
106            "v2_4" => Ok(Self::V2_4),
107            other => Err(GenerationParseError {
108                unrecognized: other.to_owned(),
109            }),
110        }
111    }
112}
113
114// canonical-JSON `serde` impls (openehr-codegen -- emit-json), auto-declared:
115mod json_serde;