facet-dom
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 ;
// Parser emits events, deserializer consumes them
let parser:
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.
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.