Skip to main content

ifc_schema/
version.rs

1//! Which IFC schema version a file declares.
2//!
3//! The token comes from the `FILE_SCHEMA` entry in a STEP header. Real files
4//! carry variants (`IFC4X3_ADD2` as well as `IFC4X3`), so matching is explicit
5//! rather than a prefix test.
6
7/// Which IFC schema version a table describes.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum SchemaVersion {
10    /// IFC2x3 TC1 — 653 entities. Still the most common in the wild.
11    Ifc2x3,
12    /// IFC4 ADD2 TC1 — 776 entities. The ISO-standard release.
13    Ifc4,
14    /// IFC4x3 ADD2 — 876 entities. Adds alignment and civil infrastructure.
15    Ifc4x3,
16}
17
18impl SchemaVersion {
19    /// Parse the token found in a STEP file's `FILE_SCHEMA` header entry.
20    pub fn from_header_token(token: &str) -> Option<Self> {
21        match token.trim().to_ascii_uppercase().as_str() {
22            "IFC2X3" => Some(Self::Ifc2x3),
23            "IFC4" => Some(Self::Ifc4),
24            "IFC4X3" | "IFC4X3_ADD2" => Some(Self::Ifc4x3),
25            _ => None,
26        }
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn recognizes_the_schema_tokens_our_fixtures_carry() {
36        assert_eq!(
37            SchemaVersion::from_header_token("IFC4"),
38            Some(SchemaVersion::Ifc4)
39        );
40        assert_eq!(
41            SchemaVersion::from_header_token("ifc2x3"),
42            Some(SchemaVersion::Ifc2x3)
43        );
44        assert_eq!(SchemaVersion::from_header_token("STEP"), None);
45    }
46}