Skip to main content

ifc_lite_core/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! # IFC-Lite Core Parser
6//!
7//! High-performance STEP/IFC parser built with [nom](https://docs.rs/nom).
8//! Provides zero-copy tokenization and fast entity scanning for IFC files.
9//!
10//! ## Overview
11//!
12//! This crate provides the core parsing functionality for IFC-Lite:
13//!
14//! - **STEP Tokenization**: Zero-copy parsing of STEP file format
15//! - **Entity Scanning**: SIMD-accelerated entity discovery using [memchr](https://docs.rs/memchr)
16//! - **Lazy Decoding**: On-demand attribute parsing for memory efficiency
17//! - **Streaming Parser**: Event-based parsing for large files
18//!
19//! ## Quick Start
20//!
21//! ```rust,ignore
22//! use ifc_lite_core::{EntityScanner, parse_entity, IfcType};
23//!
24//! // Scan for entities
25//! let content = br#"#1=IFCPROJECT('guid',$,$,$,$,$,$,$,$);"#;
26//! let mut scanner = EntityScanner::new(content);
27//!
28//! while let Some((id, type_name, start, end)) = scanner.next_entity() {
29//!     println!("Found entity #{}: {}", id, type_name);
30//! }
31//!
32//! // Parse individual entity
33//! let input = b"#123=IFCWALL('guid',$,$,$,$,$,$,$);";
34//! let (id, ifc_type, attrs) = parse_entity(input).unwrap();
35//! assert_eq!(ifc_type, IfcType::IfcWall);
36//! ```
37//!
38//! ## Streaming Parser
39//!
40//! For large files, use the streaming parser to process entities in batches:
41//!
42//! ```rust,ignore
43//! use ifc_lite_core::{parse_stream, StreamConfig, ParseEvent};
44//!
45//! let config = StreamConfig::default();
46//! for event in parse_stream(content, config) {
47//!     match event {
48//!         ParseEvent::Entity { id, type_name, .. } => {
49//!             println!("Entity #{}: {}", id, type_name);
50//!         }
51//!         ParseEvent::Progress { percent, .. } => {
52//!             println!("Progress: {:.1}%", percent);
53//!         }
54//!         _ => {}
55//!     }
56//! }
57//! ```
58//!
59//! ## Performance
60//!
61//! - **Tokenization**: ~1,259 MB/s throughput
62//! - **Entity scanning**: ~650 MB/s with SIMD acceleration
63//! - **Number parsing**: 10x faster than std using [lexical-core](https://docs.rs/lexical-core)
64
65pub mod columnar_index;
66pub mod decoder;
67pub mod error;
68pub mod fast_parse;
69pub mod generated;
70pub mod georef;
71pub mod legacy_entities;
72pub mod model_bounds;
73pub mod parser;
74pub mod project_units;
75pub mod schema_gen;
76pub(crate) mod schema_helpers;
77pub mod step_encoding;
78pub mod streaming;
79pub mod units;
80
81pub use columnar_index::ColumnarEntityIndex;
82pub use decoder::{build_entity_index, EntityDecoder, EntityIndex};
83pub use error::{Error, Result};
84pub use fast_parse::{
85    extract_coordinate_list_from_entity, extract_entity_refs_from_list, extract_entity_type_name,
86    extract_face_indices_from_entity, extract_first_entity_ref, parse_coordinates_direct,
87    parse_indices_direct, process_triangulated_faceset_direct, should_use_fast_path, FastMeshData,
88};
89pub use generated::IfcType;
90pub use georef::{GeoRefExtractor, GeoRefSource, GeoReference, RtcOffset};
91pub use legacy_entities::{
92    get_legacy_entity_info, is_legacy_entity, map_legacy_to_base_type, LegacyEntityInfo,
93};
94pub use model_bounds::{scan_model_bounds, scan_placement_bounds, ModelBounds};
95pub use parser::{entity_count, parse_entity, EntityScanner, Token};
96pub use project_units::{
97    measure::{measure_unit, MeasureUnit},
98    resolve_unit_by_ref, ProjectUnits, ResolvedUnit,
99};
100pub use schema_gen::{AttributeValue, DecodedEntity, GeometryCategory, IfcSchema, ProfileCategory};
101pub use schema_helpers::{has_geometry_by_name, is_simple_geometry_type, legacy_aware_ifc_type};
102pub use step_encoding::{decode_ifc_string, encode_ifc_string};
103pub use streaming::{parse_stream, ParseEvent, StreamConfig};
104pub use units::{
105    extract_length_unit_scale, extract_plane_angle_to_radians, get_si_prefix_multiplier,
106    try_extract_length_unit_scale, try_extract_plane_angle_to_radians,
107};