openehr-base 0.0.76

openEHR BASE foundation + base types, generated from BMM: generations v1_2 (BASE 1.2.0) and v1_3 (BASE 1.3.0, current)
Documentation
// @generated by openehr-codegen — DO NOT EDIT.
// SPDX-FileCopyrightText: Vernum Projecten B.V.
// SPDX-FileCopyrightText: openEHR Foundation
// SPDX-License-Identifier: Apache-2.0
//! openEHR BASE (foundation + base types), generated from the BMM meta-model.
//!
//! The type files are generated; hand-written spec behaviour
//! lives in sibling `*_impl.rs` files.

#![allow(
    clippy::doc_markdown,
    clippy::doc_link_with_quotes,
    clippy::tabs_in_doc_comments,
    clippy::doc_lazy_continuation,
    clippy::doc_overindented_list_items,
    clippy::struct_excessive_bools,
    clippy::struct_field_names,
    clippy::module_inception,
    clippy::large_enum_variant,
    clippy::enum_variant_names,
    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)"
)]
// 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.
#![expect(
    clippy::pub_use,
    reason = "the generation preludes are this crate's public surface"
)]
// 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.
#![recursion_limit = "512"]

pub mod prelude;
pub mod v1_2;
pub mod v1_3;

/// The BMM generations this crate emits, one variant per version module,
/// oldest first.
///
/// Generated from the openehr-codegen composition table — the single
/// authority for which generations exist. [`std::fmt::Display`] and
/// [`std::str::FromStr`] round-trip the generation-module name (`"v1_2"`). `Generation::default()` is the crate's CURRENT generation — the
/// one `crate::prelude` re-exports (the composition table's `current`
/// marker, via the std `#[default]` variant attribute).
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Generation {
    /// The `v1_2` generation — openEHR specification version 1.2.0.
    V1_2,
    /// The `v1_3` generation — openEHR specification version 1.3.0.
    #[default]
    V1_3,
}

impl Generation {
    /// Returns the openEHR specification version this generation implements.
    #[must_use]
    pub const fn spec_version(self) -> &'static str {
        match self {
            Self::V1_2 => "1.2.0",
            Self::V1_3 => "1.3.0",
        }
    }

    /// Returns the generation token — the version-module name
    /// (`"v1_3"`), which is also the [`std::fmt::Display`] and
    /// [`std::str::FromStr`] form.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::V1_2 => "v1_2",
            Self::V1_3 => "v1_3",
        }
    }
}

impl std::fmt::Display for Generation {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

/// Error returned when parsing a [`Generation`] from an unknown token.
///
/// The valid tokens are the generation-module names (`v1_2`, `v1_3`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GenerationParseError {
    unrecognized: String,
}

impl std::fmt::Display for GenerationParseError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "unknown generation {:?} (valid: `v1_2`, `v1_3`)",
            self.unrecognized
        )
    }
}

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

impl std::str::FromStr for Generation {
    type Err = GenerationParseError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "v1_2" => Ok(Self::V1_2),
            "v1_3" => Ok(Self::V1_3),
            other => Err(GenerationParseError {
                unrecognized: other.to_owned(),
            }),
        }
    }
}

// hand-written modules (spec behaviour), auto-declared:
pub mod containers;
pub mod serde_support;
pub mod validate;

// canonical-JSON `serde` impls (openehr-codegen -- emit-json), auto-declared:
mod json_serde;