Expand description
§rdom-core — arena-backed DOM for Rust
A pure DOM tree with no rendering dependencies. Node / Element / Text / Comment / Fragment types, full tree mutation, attributes, classes, and (in later phases) query selectors, events, and O(1) index lookups.
Designed to be paired with rdom-tui for terminal rendering, or used
standalone for headless tree manipulation, tests, templates, and
hypothetical alternative renderers.
§Quick tour
use rdom_core::{Dom, AdjacentPosition};
let mut dom: Dom = Dom::new();
let root = dom.root();
let hero = dom.create_element("div");
dom.node_mut(hero).set_id("hero").unwrap();
dom.node_mut(hero).add_class("active").unwrap();
let title = dom.create_element("h1");
let text = dom.create_text_node("Welcome");
dom.node_mut(title).append_child(text).unwrap();
dom.node_mut(hero).append_child(title).unwrap();
dom.node_mut(root).append_child(hero).unwrap();
assert_eq!(dom.node(root).child_element_count(), 1);
assert_eq!(dom.node(hero).first_element_child().unwrap().tag_name(), Some("h1"));Modules§
- selectors
- CSS selector grammar — tokenizer + parser + AST.
Structs§
- Abort
Controller - The write end of an abort pair — fires the signal via
abort. - Abort
Signal - The read end of an abort pair — carried by listeners so dispatch can check whether they should still fire.
- Child
Iter - Iterator over all direct children (any node type), in document order.
- Document
Position - Bitflags matching MDN’s
Node.compareDocumentPositionreturn value. Multiple bits can be set — e.g.CONTAINED_BY | FOLLOWINGwhen the other node is a descendant (descendants are considered “following” in document order). - Dom
- DomString
Map - Read-side view of
el.dataset. Borrows the element viaNodeRef; lookup converts a camelCase key to adata-*attribute name on the fly. - DomString
MapMut - Write-side view of
el.dataset. Borrows the element viaNodeMut; mutations route throughset_attribute/remove_attributeso the existing attribute-change mutation observer fires. - DomToken
List - Snapshot of an element’s ordered class tokens (DOM
Element.classListread-side view). Re-construct via the element accessor to refresh after a class mutation. - DomToken
List Mut - Mutable handle to an element’s class tokens. Holds a
NodeMutso mutations route through the existing class-set machinery (add_class/remove_class/replace_class), keeping cascade dirty-tracking and the per-class index in sync. - Element
Child Iter - Iterator over element children only.
- Event
- Minimal event — just routing state. Attach payload via a typed
wrapper in
rdom-tuior the caller’s crate. - Event
Ctx - Context passed to a handler: mutable Event + mutable Dom.
- Html
Collection - Snapshot of element ids captured at construction with
name-based lookup. Used by
form.elements,getElementsByTagName, etc. - Input
Detail beforeinput/inputevent payload, per UI Events / Input Events Level 2.- Keyboard
Detail keydown/keypress/keyuppayload.- Keyboard
Modifiers - Four-boolean modifier set, matching the
KeyboardEvent.{ctrl,shift,alt,meta}KeyandMouseEvent.{ctrl,shift,alt,meta}Keyaccessor shape. - Listener
Id - Handle returned from
add_event_listener— pass toremove_event_listenerto detach this specific registration. - Listener
Options - Options for
add_event_listener— matches the DOM spec object. - Mouse
Detail - Pointer event payload —
click,mousedown,mouseup,mousemove,wheel,contextmenu. - NodeId
- Node
List - Snapshot of node ids captured at construction.
item(i)anditer()resolve against the borrowed&Dom; if a node has been removed since the snapshot, the resolution returnsNonefor that slot (filtered out byiter()). - NodeMut
- Mutable handle. All mutations go through this wrapper so future index maintenance hooks (Phase 4) have a single chokepoint.
- NodeRef
- Read-only handle to a node in the arena.
- Observer
Id - Handle returned from
add_mutation_observer. Pass toremove_mutation_observerto unregister. - Position
- A position within the DOM’s text content.
- Range
- A range of text in document order —
startprecedes or equalsend. Built in document order byDom::selection_range, which accepts any two positions and sorts them;Range::ordered_uncheckedtrusts the caller’s order. - Selection
- Document-level selection. Two positions —
anchorat the start of the interaction (e.g., mousedown, Shift+Click origin) andfocusat the current cursor position. - Selection
Serial - A reading of
Dom::selection_serial: a counter that advances on every actual selection change. Two equal readings mean the selection was not touched in between; a later reading compares greater (the counter is au64, so it does not wrap in practice). An opaque bookkeeping value — no web API exposes it;new/getexist for tests and for backends that persist a reading. - Submit
Detail submitevent payload, per HTML §4.10.21.3 form submission.- Toggle
Detail toggleevent payload — emitted by<details>and<dialog>when their open/closed state changes.- Transition
Detail transitionstart/transitionend/transitioncancelevent payload. CSS Transitions Level 1 §5.1.
Enums§
- Activation
Phase - Which activation step the Dom’s hook is being asked to run.
- Adjacent
Position - Position relative to a reference node, for
insert_adjacent*. - Content
Editable State - A
contenteditableattribute’s explicit state (HTML §6.8.1). The inherit state is the absence of one (None). - DomError
- Event
Detail - Typed payload carried on
Event::detail. - Event
Phase - Which phase of dispatch is currently running.
- Form
Enctype - A form’s entry-list encoding — the
enctype/formenctypeenumerated attribute (HTML §4.10.19.6). Keywords are ASCII case-insensitive; the missing and invalid value default isUrlEncoded. - Form
Method - A form’s submission method — the
method/formmethodenumerated attribute (HTML §4.10.19.6). Keywords are ASCII case-insensitive; the missing and invalid value default isGet. - Input
Type - UI Events
InputEvent.inputTypevalue. - Input
Type State - The state of an
<input>’stypeattribute (HTML §4.10.5, the table of keywords and states). rdom renders only some of them; the rest are still recognized so an unshipped type such asdateis not mistaken for Text. - Interaction
Kind - Which interaction state changed. Fired by
Dom::set_hovered/Dom::set_focused/Dom::set_focus_visible/Dom::set_activeso pseudo-class matches (:hover,:focus,:focus-within,:focus-visible,:active) can invalidate cleanly.:hover,:focus-withinand:activealso match every ancestor of the element named, so theirprev/nextstand for those chains. - Invariant
Violation - Mouse
Button - DOM
MouseEvent.buttonmapping. - Mutation
- One DOM mutation notification.
- Node
Data - Per-type payload.
- Node
OrString - Either an existing node (by id) or a string to be wrapped in a
fresh text node. Built via
Fromimpls so call sites read naturally — see module docs for an example. - Node
Type - DOM-spec node types with the numeric values the spec assigns.
- Toggle
State - Open/closed state for
<details>and<dialog>toggleevent detail.
Constants§
- VOID_
ELEMENTS - The void elements of HTML §13.3 (serialization) — elements that
never have children and are serialized without an end tag. Shared
with
rdom-parser, which treats a start tag of one of these as the whole element; keeping one list means what the parser accepts is exactly what the serializer emits.
Traits§
- Mutation
Observer - Observer callback trait. Receives a mutable
&mut Dom<Ext>so observers can READ freely — but any attempt to mutate the tree insideobserve()panics via theis_observingguard. Installing or removing observers from inside the callback is allowed (the web’sMutationObserver.disconnect()inside the callback): a removed observer — including the one currently running — receives nothing further; an added one receives only later records.
Functions§
- is_
void_ element - Is
tag(lowercase) one ofVOID_ELEMENTS?
Type Aliases§
- Activation
Hook - The Dom’s activation-behavior hook (DOM §2.9 steps 5.5 and 11). One
per
Dom; it receives every dispatched event and decides by target and event type whether the target has activation behavior. Runs regardless ofstopPropagation(). - Form
Controls Collection - Alias for
form.elements’s return type. The web platform distinguishes these at the IDL level but uses the same shape; rdom collapses them to a single struct + a type alias. - Result
- Validity
Hook - A backend’s constraint check: whether candidate
idsatisfies its constraints. The validity states need values, patterns and state the substrate does not model (rdom-tui’svalidationbuiltin computes them), so the substrate asks the backend through this hook — a plainfn, so matching (&self) can call it. Installed withDom::set_validity_hook.