#dom #html #deserialize #xml #facet

facet-dom

Tree-based (DOM) deserializer for facet - supports HTML and XML

4 releases (2 breaking)

Uses new Rust 2024

new 0.44.0 Mar 1, 2026
0.43.1 Jan 23, 2026
0.43.0 Jan 22, 2026
0.0.0 Jan 22, 2026

#2955 in Parser implementations


Used in 5 crates (2 directly)

MIT/Apache

260KB
5K SLoC

facet-dom

crates.io documentation MIT/Apache-2.0 licensed Discord

Tree-based (DOM) serialization and deserialization for facet.

Overview

This crate provides the core serializers and deserializers for tree-structured documents like HTML and XML. It handles the DOM-specific concerns that don't apply to flat formats like JSON:

  • Tag names: Elements have names (<div>, <person>)
  • Attributes: Key-value pairs on elements (id="main", class="active")
  • Mixed content: Text and child elements can be interleaved

Architecture

facet-dom sits between the format-specific parsers (facet-html, facet-xml) and the generic facet reflection system:

facet-html / facet-xml
         ↓
     facet-dom  (DOM events: StartElement, Attribute, Text, EndElement)
         ↓
   facet-reflect (Peek/Poke)
         ↓
    Your Rust types

Key Types

DomDeserializer

Consumes DOM events and builds Rust values:

use facet_dom::{DomDeserializer, DomParser};

// Parser emits events, deserializer consumes them
let parser: impl DomParser = /* ... */;
let value: MyType = DomDeserializer::new(parser).deserialize()?;

DomSerializer

Converts Rust values to DOM events for output.

Field Mappings

The deserializer maps DOM concepts to Rust types using facet attributes:

DOM Concept Rust Representation Attribute
Tag name Struct variant #[facet(rename = "tag")]
Attribute Field #[facet(html::attribute)]
Text content String field #[facet(html::text)]
Child elements Vec field #[facet(html::elements)]

Naming Conventions

Handles automatic case conversion between DOM naming (kebab-case) and Rust naming (snake_case), plus singularization for collection fields.

Part of the Facet Ecosystem

This crate is part of the facet ecosystem, providing reflection for Rust.

License

Licensed under either of:

at your option.

Dependencies

~5–8.5MB
~126K SLoC