openbim_epd/lib.rs
1//! `openbim-epd` — ISO 22057 EPD data-template contracts.
2//!
3//! ISO 22057:2022 defines data templates for using environmental product
4//! declaration (EPD) information in building information modelling. It builds
5//! on the data-template concepts from ISO 23387 and the life-cycle modules used
6//! by construction-product EPDs.
7//!
8//! # No ISO 22057 XML schema
9//!
10//! ISO 22057 defines the information structure and mappings; it does **not**
11//! standardize one XML namespace, XSD, or wire encoding. Its informative mapping
12//! material references multiple established exchange formats. Consequently this
13//! crate deliberately exposes no invented ISO 22057 XML namespace and does not
14//! claim that XML parsing exists.
15//!
16//! # Status
17//!
18//! **Format-neutral foundation.** The standard edition, all 18 EPD
19//! information-module codes (including aggregated `A1-A3`), and composition
20//! with the shared ISO 23387 [`openbim_dt::DataTemplate`] are represented and
21//! tested. This core crate does not parse, write, or validate exchange formats;
22//! versioned adapters such as `openbim-ilcd-epd` remain separate packages.
23//!
24//! # Examples
25//!
26//! ```
27//! use openbim_epd::{InformationModule, InformationModuleGroup, StandardEdition};
28//!
29//! assert_eq!(StandardEdition::CURRENT.designation(), "ISO 22057:2022");
30//! assert_eq!(InformationModule::A1ToA3.code(), "A1-A3");
31//! assert_eq!(
32//! InformationModule::D.group(),
33//! InformationModuleGroup::BeyondSystemBoundary
34//! );
35//! ```
36//!
37//! # Repository boundary
38//!
39//! EPD consumes shared data-template and, eventually, IFC contracts. IFC, core,
40//! and codec crates must never depend on EPD. The `openbimrs/openbim`
41//! integration repository pins compatible family revisions without reversing
42//! that dependency direction.
43
44#![forbid(unsafe_code)]
45
46/// An edition of the EPD data-template standard represented by this crate.
47#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
48pub enum StandardEdition {
49 /// ISO 22057:2022, the first published edition.
50 Iso22057_2022,
51}
52
53impl StandardEdition {
54 /// The edition used for new EPD data-template work.
55 pub const CURRENT: Self = Self::Iso22057_2022;
56
57 /// The normative standard designation.
58 #[must_use]
59 pub const fn designation(self) -> &'static str {
60 match self {
61 Self::Iso22057_2022 => "ISO 22057:2022",
62 }
63 }
64}
65
66/// An ISO 22057 EPD template composed from the ISO 23387 vocabulary.
67///
68/// ISO 22057 specializes BIM data-template concepts; it does not own a second
69/// property, unit, quantity-kind, or object-type model. Keeping the underlying
70/// [`openbim_dt::DataTemplate`] intact gives EPD and LOIN the same type identity
71/// without making either standard depend on the other.
72///
73/// This type is format-neutral. It does not imply ILCD+EPD XML, provider API,
74/// or Annex A conformance.
75#[derive(Debug, Clone, PartialEq, Eq)]
76pub struct EpdDataTemplate {
77 standard: StandardEdition,
78 data_template: openbim_dt::DataTemplate,
79}
80
81impl EpdDataTemplate {
82 /// Binds an ISO 23387 data template to the current ISO 22057 edition.
83 #[must_use]
84 pub const fn new(data_template: openbim_dt::DataTemplate) -> Self {
85 Self {
86 standard: StandardEdition::CURRENT,
87 data_template,
88 }
89 }
90
91 /// The ISO 22057 edition governing this EPD template.
92 #[must_use]
93 pub const fn standard(&self) -> StandardEdition {
94 self.standard
95 }
96
97 /// The shared ISO 23387 data-template contract.
98 #[must_use]
99 pub const fn data_template(&self) -> &openbim_dt::DataTemplate {
100 &self.data_template
101 }
102
103 /// Consumes the EPD binding and returns the shared ISO 23387 template.
104 #[must_use]
105 pub fn into_data_template(self) -> openbim_dt::DataTemplate {
106 self.data_template
107 }
108}
109
110/// A semantic grouping for EPD information-module codes.
111///
112/// This is deliberately broader than a life-cycle stage: module D represents
113/// benefits and loads beyond the product-system boundary.
114#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
115pub enum InformationModuleGroup {
116 /// Product stage: modules A1 to A3 and the aggregated A1-A3 value.
117 Product,
118 /// Construction-process stage: modules A4 and A5.
119 ConstructionProcess,
120 /// Use stage: modules B1 to B7.
121 Use,
122 /// End-of-life stage: modules C1 to C4.
123 EndOfLife,
124 /// Benefits and loads beyond the product-system boundary: module D.
125 BeyondSystemBoundary,
126}
127
128/// One of the 18 EPD information-module codes from A1 through D.
129///
130/// `A1ToA3` represents the aggregated `A1-A3` value that appears alongside
131/// the individual A1, A2, and A3 values in the ISO 22057 template.
132#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
133pub enum InformationModule {
134 /// Raw-material supply.
135 A1,
136 /// Transport to the manufacturer.
137 A2,
138 /// Manufacturing.
139 A3,
140 /// Aggregated product stage covering A1, A2, and A3.
141 A1ToA3,
142 /// Transport to the construction site.
143 A4,
144 /// Construction and installation.
145 A5,
146 /// Use.
147 B1,
148 /// Maintenance.
149 B2,
150 /// Repair.
151 B3,
152 /// Replacement.
153 B4,
154 /// Refurbishment.
155 B5,
156 /// Operational energy use.
157 B6,
158 /// Operational water use.
159 B7,
160 /// Deconstruction and demolition.
161 C1,
162 /// Transport during end of life.
163 C2,
164 /// Waste processing.
165 C3,
166 /// Disposal.
167 C4,
168 /// Benefits and loads beyond the system boundary.
169 D,
170}
171
172impl InformationModule {
173 /// Every module in normative order.
174 pub const ALL: [Self; 18] = [
175 Self::A1,
176 Self::A2,
177 Self::A3,
178 Self::A1ToA3,
179 Self::A4,
180 Self::A5,
181 Self::B1,
182 Self::B2,
183 Self::B3,
184 Self::B4,
185 Self::B5,
186 Self::B6,
187 Self::B7,
188 Self::C1,
189 Self::C2,
190 Self::C3,
191 Self::C4,
192 Self::D,
193 ];
194
195 /// The compact module code used by EPD datasets.
196 #[must_use]
197 pub const fn code(self) -> &'static str {
198 match self {
199 Self::A1 => "A1",
200 Self::A2 => "A2",
201 Self::A3 => "A3",
202 Self::A1ToA3 => "A1-A3",
203 Self::A4 => "A4",
204 Self::A5 => "A5",
205 Self::B1 => "B1",
206 Self::B2 => "B2",
207 Self::B3 => "B3",
208 Self::B4 => "B4",
209 Self::B5 => "B5",
210 Self::B6 => "B6",
211 Self::B7 => "B7",
212 Self::C1 => "C1",
213 Self::C2 => "C2",
214 Self::C3 => "C3",
215 Self::C4 => "C4",
216 Self::D => "D",
217 }
218 }
219
220 /// Resolves an exact, case-sensitive EPD module code.
221 #[must_use]
222 pub const fn from_code(code: &str) -> Option<Self> {
223 match code.as_bytes() {
224 b"A1" => Some(Self::A1),
225 b"A2" => Some(Self::A2),
226 b"A3" => Some(Self::A3),
227 b"A1-A3" => Some(Self::A1ToA3),
228 b"A4" => Some(Self::A4),
229 b"A5" => Some(Self::A5),
230 b"B1" => Some(Self::B1),
231 b"B2" => Some(Self::B2),
232 b"B3" => Some(Self::B3),
233 b"B4" => Some(Self::B4),
234 b"B5" => Some(Self::B5),
235 b"B6" => Some(Self::B6),
236 b"B7" => Some(Self::B7),
237 b"C1" => Some(Self::C1),
238 b"C2" => Some(Self::C2),
239 b"C3" => Some(Self::C3),
240 b"C4" => Some(Self::C4),
241 b"D" => Some(Self::D),
242 _ => None,
243 }
244 }
245
246 /// The semantic group containing this information-module code.
247 ///
248 /// Module D returns [`InformationModuleGroup::BeyondSystemBoundary`]; it is
249 /// deliberately not described as a life-cycle stage.
250 #[must_use]
251 pub const fn group(self) -> InformationModuleGroup {
252 match self {
253 Self::A1 | Self::A2 | Self::A3 | Self::A1ToA3 => InformationModuleGroup::Product,
254 Self::A4 | Self::A5 => InformationModuleGroup::ConstructionProcess,
255 Self::B1 | Self::B2 | Self::B3 | Self::B4 | Self::B5 | Self::B6 | Self::B7 => {
256 InformationModuleGroup::Use
257 }
258 Self::C1 | Self::C2 | Self::C3 | Self::C4 => InformationModuleGroup::EndOfLife,
259 Self::D => InformationModuleGroup::BeyondSystemBoundary,
260 }
261 }
262}
263
264#[cfg(test)]
265mod tests {
266 use super::*;
267
268 #[test]
269 fn current_edition_has_the_normative_designation() {
270 assert_eq!(StandardEdition::CURRENT.designation(), "ISO 22057:2022");
271 }
272
273 #[test]
274 fn information_modules_are_complete_and_round_trip() {
275 const EXPECTED_CODES: [&str; 18] = [
276 "A1", "A2", "A3", "A1-A3", "A4", "A5", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "C1",
277 "C2", "C3", "C4", "D",
278 ];
279
280 assert_eq!(
281 InformationModule::ALL.map(InformationModule::code),
282 EXPECTED_CODES
283 );
284
285 for module in InformationModule::ALL {
286 assert_eq!(InformationModule::from_code(module.code()), Some(module));
287 }
288 }
289
290 #[test]
291 fn information_modules_map_to_their_groups() {
292 assert_eq!(
293 InformationModule::A1.group(),
294 InformationModuleGroup::Product
295 );
296 assert_eq!(
297 InformationModule::A3.group(),
298 InformationModuleGroup::Product
299 );
300 assert_eq!(
301 InformationModule::A1ToA3.group(),
302 InformationModuleGroup::Product
303 );
304 assert_eq!(
305 InformationModule::A4.group(),
306 InformationModuleGroup::ConstructionProcess
307 );
308 assert_eq!(InformationModule::B7.group(), InformationModuleGroup::Use);
309 assert_eq!(
310 InformationModule::C4.group(),
311 InformationModuleGroup::EndOfLife
312 );
313 assert_eq!(
314 InformationModule::D.group(),
315 InformationModuleGroup::BeyondSystemBoundary
316 );
317 }
318
319 #[test]
320 fn unknown_module_codes_are_rejected() {
321 assert_eq!(InformationModule::from_code("A0"), None);
322 assert_eq!(InformationModule::from_code("a1"), None);
323 assert_eq!(InformationModule::from_code(""), None);
324 }
325}