openehr_lang/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 LANG, generated from the BMM meta-model: one generation per component version. `v1_1` (the 1.1.0 development line, the current generation) carries the version's published specification units side by side — the STABLE, tool-implemented BMM v2.x model (`bmm`, its `bmm_persistence` P_BMM form, the `beom` BEL expression model; on the prelude) and the PAUSED BMM3 model (`bmm3`, full-path only) — plus the hand-written ODIN/BEL/EL readers and the shared lexer for that version's notations. The generator's own BMM reader lives in openehr-codegen (tooling, not spec).
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_0;
33pub mod v1_1;
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_0"`). `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_0` generation — openEHR specification version 1.0.0.
46 V1_0,
47 /// The `v1_1` generation — openEHR specification version 1.1.0.
48 #[default]
49 V1_1,
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_0 => "1.0.0",
58 Self::V1_1 => "1.1.0",
59 }
60 }
61
62 /// Returns the generation token — the version-module name
63 /// (`"v1_1"`), 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_0 => "v1_0",
69 Self::V1_1 => "v1_1",
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_0`, `v1_1`).
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_0`, `v1_1`)",
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_0" => Ok(Self::V1_0),
106 "v1_1" => Ok(Self::V1_1),
107 other => Err(GenerationParseError {
108 unrecognized: other.to_owned(),
109 }),
110 }
111 }
112}
113
114// hand-written modules (spec behaviour), auto-declared:
115pub mod nesting;
116
117// canonical-JSON `serde` impls (openehr-codegen -- emit-json), auto-declared:
118mod json_serde;