Rust Core¶
The native accelerator is a PyO3 crate at src/crxml_core/.
Crate structure¶
CrxmlReader¶
A single Python-exposed class:
#[pyclass]
struct CrxmlReader {
source: PathBuf,
row_tag: String,
buf: Vec<u8>,
inner_buf: Vec<u8>,
}
__iter__, returnsself__next__, reads the next row as aPyDict
The reader walks the XML stream, finds <row_tag> elements, and extracts
field key/value pairs from nested <Field> and <Text> elements.
Dependencies¶
| Crate | Purpose |
|---|---|
pyo3 |
Python bindings |
quick-xml |
Streaming XML reader |
simdutf8 |
SIMD-accelerated UTF-8 validation for parse chunks |
memchr |
Fast byte searching (direct dependency, also used by quick-xml) |
mimalloc |
Fast allocator (replaces system malloc, ~27% CPU savings) |
Building¶
The pyproject.toml [tool.maturin] section controls the build:
Code style¶
- Rust 2021 edition
cargo fmtfor formattingcargo clippy, no warnings allowed- Unsafe code is denied by default (
#![deny(unsafe_code)])
Testing¶
# Rust unit tests
cargo test --manifest-path src/crxml_core/Cargo.toml
# Integration via Python
python -c "from crxml._crxml_core import CrxmlReader; r = CrxmlReader('test.xml', 'Details'); print(next(r))"
Security¶
- Unsafe denied by default (
#![deny(unsafe_code)]). Twounsafeblocks guarded by#[allow(unsafe_code)]handleMmap::map(mmap I/O) andfrom_utf8_unchecked(SIMD-validated UTF-8). The_PyDict_NewPresizedprivate-CAPI call was removed after benchmarking showed only a 3.5% overall gain. - Input validation, XML is assumed trusted (users control their source files). Buffer sizes are managed by quick-xml.
- Buffer limits, individual field values are bounded by the XML entity size. No unbounded allocations.