Skip to main content

Rust Crates

The Rust side is organized as a layered workspace with 10 crates. Each crate has a single responsibility.

Dependency graph​

docxio-types
↑
docxio-ooxml
↑
docxio-core
↑
├── docxio-wasm
├── docxio-wasm-minimal
├── docxio-napi
├── docxio-cli
├── docxio-pdf
├── docxio-bench
└── docxio-fuzz

Crate responsibilities​

docxio-types​

Shared document model types. Defines DocumentTree, DocumentNode, and all property structs (ParagraphProps, RunProps, TableProps, etc.).

  • Derives serde::Serialize and serde::Deserialize with rename_all = "camelCase" for JS interop
  • No XML or ZIP dependencies
  • Used by every other crate in the workspace

docxio-ooxml​

OOXML XML generation using quick-xml. Stateless functions that take typed Rust structs and produce XML byte output.

Key modules:

  • document_xml.rs -- word/document.xml
  • styles_xml.rs -- word/styles.xml
  • numbering_xml.rs -- word/numbering.xml
  • header_xml.rs / footer_xml.rs -- header/footer parts
  • drawing_xml.rs -- image drawing elements
  • relationships.rs -- .rels relationship files
  • content_types.rs -- [Content_Types].xml
  • sanitize module -- validates and clamps colors, sizes, dimensions to OOXML spec ranges

docxio-core​

Orchestration layer. Walks the document tree, calls docxio-ooxml to generate XML parts, and assembles them into a ZIP archive.

Key modules:

  • render.rs -- Tree walker, calls OOXML generators
  • builder.rs -- Document builder API
  • parser.rs -- JSON-to-DocumentTree parsing
  • template.rs -- Template patching ({{placeholder}} replacement)
  • validate.rs -- OOXML structure validation
  • media.rs -- Image registry and embedding
  • rel_manager.rs -- Relationship ID management

docxio-wasm​

Full WebAssembly binding (~920 KB). Exposes generate(), patch(), and validate() entry points via wasm-bindgen. Includes ZIP packaging, template engine, and validator.

docxio-wasm-minimal​

Minimal WebAssembly binding (~441 KB). Exposes generate_document_parts() which returns XML parts without ZIP assembly. Used with @docxio/zip for browser-optimized builds.

docxio-napi​

Native Node.js binding via napi-rs. Exposes a #[napi] generate() function for maximum server-side performance without WASM overhead.

docxio-cli​

Command-line tool built with clap:

  • docxio generate -i doc.json -o output.docx -- generate from JSON
  • docxio patch template.docx data.json -o filled.docx -- template patching
  • docxio watch -i doc.json -o output.docx -- rebuild on file changes

docxio-pdf​

PDF export via printpdf. Currently planned and not yet functional.

docxio-bench​

Benchmarks using criterion. Measures XML generation, ZIP assembly, and end-to-end rendering performance.

docxio-fuzz​

Fuzz testing targets for the document parser and renderer. Helps discover edge cases and potential panics.

Workspace configuration​

All crates inherit workspace-level lints and formatting rules:

  • clippy.toml + [workspace.lints] for consistent Clippy rules
  • rustfmt.toml for formatting
  • unsafe_code = "deny" across all crates
  • overflow-checks = true in release builds