Documentation
Zero-Unsafe Architecture
Designed for maximum memory safety and performance: `#![forbid(unsafe_code)]`, arena allocation, and SIMD scanning.
Zero Unsafe Rule
oxml strictly enforces #![forbid(unsafe_code)] at crate root across all crates in the workspace. There are zero exceptions:
- No raw pointer arithmetic
- No unverified memory transmutes
- No unchecked slice access
Every boundary check is verified at compile-time or hardware-accelerated without compromising memory safety.
Arena Allocation
oxml::Document backs its DOM with a generational slot-recycling node arena:
- O(1) Node Lookup: Nodes are addressed via lightweight, copyable
NodeIdtokens. - Generational Recycling: Deleted nodes increment their slot generation counter. Accessing a stale
NodeIdsafely fails rather than pointing to dangling or reallocated memory. - Cache Locality: Nodes are stored in contiguous vectors, maximizing CPU L1/L2 cache hit rates.
SWAR Acceleration
Safe delimiter scanning uses SIMD Within A Register (SWAR) across 8-byte chunks to scan character data and attribute values, delivering over +149% throughput vs scalar scanning without unsafe intrinsics.
Ecosystem Architecture
The oxml ecosystem is cleanly separated into specialized, decoupled crates that share the zero-unsafe core:
View Mermaid source
graph TD
subgraph Core["Core Engine"]
OXML["oxml
(Parser, DOM, XPath 1.0)"]
end
subgraph Toolchain["Runtime Integrations & Tooling"]
CLI["oxml-cli
(Terminal & CI/CD)"]
WASM["oxml-wasm
(Browser WebAssembly)"]
MCP["oxml-mcp
(AI Agent JSON-RPC)"]
LSP["oxml-lsp
(IDE Language Server)"]
JSON["oxml-json
(JSON/Streaming Converter)"]
XSD["xmlschema
(W3C XSD Conformance)"]
end
OXML --> CLI
OXML --> WASM
OXML --> MCP
OXML --> LSP
OXML --> JSON
OXML --> XSDZero-Copy Streaming Borrowing
For high-throughput pipelines where memory allocation overhead must be eliminated:
Reader::next_borrowed()yieldsBorrowedEvent<'a>items that borrow string slices directly from the internal input buffer.- Text nodes, tag names, and attribute values are inspected with zero heap copies.
- Preserves bounded 34 KB memory usage while streaming multi-gigabyte documents at peak throughput.
View Mermaid source
sequenceDiagram
autonumber
participant Stream as Input Stream (Multi-GB)
participant Ring as 34 KB Ring Buffer
participant Event as BorrowedEvent (&str)
participant App as Application Logic
Stream->>Ring: Fill internal chunk
Ring->>Event: Borrow slice without heap allocation
Event->>App: Inspect Tag / Attribute / Text
App-->>Ring: Release slice & advance ring buffer pointer