Skip to main content

energyml_core/
lib.rs

1//! Runtime support for generated EnergyML crates.
2//!
3//! This crate holds everything the generated `eml` / `resqml` / `witsml` /
4//! `prodml` crates lean on, and nothing schema-specific. It is deliberately free
5//! of native dependencies so generated code stays usable from `wasm32`.
6//!
7//! What a generated type gets:
8//!
9//! - [`xml`] - namespace-aware XML reading and writing, with explicit control of
10//!   prefixes and `xsi:type`. Serde handles JSON only.
11//! - [`reflect`] - a `&'static TypeInfo` per type: fields, XSD cardinality,
12//!   facets, documentation, accepted types for polymorphic fields.
13//! - [`value`] - object-safe dynamic access, so a UI can walk and complete an
14//!   instance it has no compile-time knowledge of.
15//! - [`path`] - `Citation.Title` style access, optionally case-insensitive.
16//! - [`validate`] - structural validation from the schema, plus a hook for
17//!   business rules.
18//! - [`registry`] - create and read objects by content type or qualified type.
19//! - [`identity_owned`] - references attributed to the data object that writes
20//!   them, stopping at nested data objects.
21//! - [`relations`] - where a type holds other data objects by value, and where it
22//!   writes references: tables written by the generator, read by byte-level scanners.
23//! - [`identifiers`] - UUID, content type, qualified type and ETP URI parsing.
24//!
25//! Generated code is written by `energyml-codegen`; the `energyml-derive` macros
26//! turn the annotated structs it emits into implementations of the traits above.
27
28#![forbid(unsafe_code)]
29
30// The derive writes `::energyml_core::...`; the unit tests of this crate use it.
31#[cfg(test)]
32extern crate self as energyml_core;
33
34pub mod any_xml;
35#[cfg(feature = "json")]
36pub mod docs;
37pub mod error;
38pub mod identifiers;
39pub mod identity;
40pub mod identity_owned;
41#[cfg(feature = "json")]
42pub mod json;
43pub mod lexical;
44pub mod measure;
45pub mod naming;
46pub mod ns;
47pub mod path;
48pub mod reflect;
49pub mod registry;
50pub mod relations;
51#[cfg(feature = "json")]
52pub mod truncate;
53pub mod validate;
54pub mod value;
55pub mod xml;
56
57pub mod prelude;
58
59pub use error::{Error, Result};
60
61/// What every object this software writes says in `Citation.Format`.
62///
63/// EML 2.3 `Abstract.xsd` l. 393-399 documents the field as *"Software or
64/// service that was used to originate the object and the file format created
65/// [...] including the organization name, software application name and
66/// software version [...] provided by the application that creates or edits
67/// the data object"*, in the form
68/// `organizationName:applicationName:applicationVersion/format`. The field is
69/// mandatory (`minOccurs="1"`), but `String2000` has no `minLength`, so an
70/// empty one passes the schema. Lutetia wrote 924 empty ones out of 1 350 until
71/// 06/10/2026, from writers that each spelled their own value or none.
72///
73/// The `/format` suffix is left out on purpose. A citation is written before
74/// anyone knows whether the object will be stored as an EPC part (XML) or pushed
75/// as JSON over ETP, so any suffix would be a guess.
76pub const CITATION_FORMAT: &str = concat!("Geosiris:energyml-rust:", env!("CARGO_PKG_VERSION"));
77
78// Re-exported so generated code can name these types through `energyml_core`
79// alone, without every generated crate having to depend on quick-xml directly.
80pub use quick_xml;
81
82/// The derive macros, re-exported so `use energyml_core::prelude::*` is the
83/// only import generated code needs.
84#[cfg(feature = "derive")]
85pub use energyml_derive::{EnergymlChoice, EnergymlEnum, EnergymlObject};